1
0
mirror of https://github.com/limosek/zaf-plugins.git synced 2024-11-01 16:27:18 +01:00
limosek-zaf-plugins/fsx/control.zaf

157 lines
3.8 KiB
Plaintext
Raw Normal View History

2016-04-04 13:59:26 +02:00
Plugin: fsx
Description::
Plugin which will make deeper look into directory structure using discovery
::
2016-04-24 05:22:57 +02:00
Version: 0.8
2016-04-04 13:59:26 +02:00
Url: https://raw.githubusercontent.com/limosek/zaf-plugins/master/fsx
Web: https://github.com/limosek/zaf-plugins/
Maintainer: Lukas Macura <lukas@macura.cz>
# Dependencies
Depends-dpkg: dash curl
Depens-opkg: busybox curl
Depends-rpm: curl
Depends-bin: curl find
2016-04-12 20:31:05 +02:00
# Sudo needed. It will be preconfigured if sudo is installed
2016-04-15 11:14:48 +02:00
Sudo: find %, {PLUGINDIR}/%sh %
2016-04-12 20:31:05 +02:00
# Cron for info about busy directories
# This is only example to get disk usage of common /var dirs
Cron::
0 */8 * * * root zaf precache fsx >/dev/null 2>/dev/null
::
2016-04-12 20:31:05 +02:00
2016-04-04 13:59:26 +02:00
Item discovery:
Description::
Discovery of files or directories.
2016-04-04 13:59:26 +02:00
::
2016-04-21 15:29:20 +02:00
Parameters::
directory '' '' # directory to scan
mask % '' # mask to search. Use % instead of * in mask. Like '%' to find all objects, '%.txt' to find all .txt files.
type d '^(d|f|l)$' # Type of objects to find (f=file,d=dir,l=link)
maxdepth 1 '' # depth to search. 1 means only one directory, not subdirs.
sort du/- '^(du|name)/([+-])$' # how to sort results (name/[+-], du/[+-]).
maxobjects 50 '' # maximum objects to find. 0 means no limit.
who zabbix '^(root|zabbix)$' # which permissions to use. Sudo must be installed for root. Default is zabbix
::
2016-04-04 13:59:26 +02:00
Type: string
2016-04-21 15:29:20 +02:00
Testparameters: /tmp/ /tmp/,%,f,1,name/+,10,root
Precache: /tmp/
Cache: 86400
2016-04-04 13:59:26 +02:00
Script::
2016-04-21 15:29:20 +02:00
case $who in
asroot|root)
2016-04-21 15:29:20 +02:00
! zaf_is_root && exec sudo -E -n $0 "$@";;
2016-04-12 20:31:05 +02:00
esac
2016-04-21 15:29:20 +02:00
mask="-name '$(echo $mask|tr '%' '*')'"
depth="-maxdepth $maxdepth"
type="-type $type"
sorttype="$(echo $sort|cut -d '/' -f 1)"
sortorder="$(echo $sort|cut -d '/' -f 2)"
[ "$sortorder" = "-" ] && so="-r"
2016-04-21 15:29:20 +02:00
if [ "$maxobjects" -gt 0 ]; then
head="head -n $maxobjects"
else
head="cat"
2016-04-04 13:59:26 +02:00
fi
2016-04-21 15:29:20 +02:00
tmpf=$ZAF_TMP_DIR/fsx$$
case $sorttype in
name)
2016-04-21 15:29:20 +02:00
zaf_dbg find "$directory" $depth $type $mask
eval find "$directory" $depth $type $mask >$tmpf
[ -s "$tmpf" ] || { echo -n "NO_OBJECTS_FOUND"; zaf_err "NO_OBJECTS_FOUND"; }
zaf_dbg sort -n $so \| $head \| zaf_discovery '{#PATH}'
sort -n $so <$tmpf | $head | zaf_discovery '{#PATH}'
;;
du)
2016-04-21 15:29:20 +02:00
zaf_dbg find "$directory" $depth $type $mask -print0
eval find "$directory" $depth $type $mask -print0 >$tmpf
[ -s "$tmpf" ] || { echo -n "NO_OBJECTS_FOUND"; zaf_err "NO_OBJECTS_FOUND"; }
zaf_dbg xargs -0 du \| sort -n $so \| $head \| zaf_discovery '{#PATH}'
xargs -0 du <$tmpf | sort -n $so | tr '\t' ' ' | cut -d ' ' -f 2 | $head |zaf_discovery '{#PATH}'
;;
esac
2016-04-21 15:29:20 +02:00
rm -f $tmpf
2016-04-04 13:59:26 +02:00
::
/Item
2016-04-24 05:22:57 +02:00
Item type:
2016-04-04 13:59:26 +02:00
Description::
Type of discovered path (d,f,l)
d - directory
f - file
l - symbolink link
::
2016-04-21 15:29:20 +02:00
Parameters::
path '' '' # Path
who zabbix '^(root|zabbix)$' # which permissions to use. Sudo must be installed for root. Default is zabbix
::
2016-04-04 13:59:26 +02:00
Type: character
2016-04-21 15:29:20 +02:00
Testparameters: /tmp/ /tmp/,root
2016-04-04 13:59:26 +02:00
Script::
2016-04-21 15:29:20 +02:00
case $who in
asroot|root)
2016-04-21 15:29:20 +02:00
! zaf_is_root && exec sudo -E -n $0 "$@";;
2016-04-12 20:31:05 +02:00
esac
2016-04-04 13:59:26 +02:00
2016-04-21 15:29:20 +02:00
[ -f "$path" ] && echo f && exit
[ -d "$path" ] && echo d && exit
[ -l "$path" ] && echo l && exit
2016-04-04 13:59:26 +02:00
::
/Item:
2016-04-24 05:22:57 +02:00
Item du:
2016-04-04 13:59:26 +02:00
Description::
Disk usage of discovered path in bytes
::
2016-04-21 15:29:20 +02:00
Parameters::
path '' '' # Path
who zabbix '^(root|zabbix)$' # which permissions to use. Sudo must be installed for root. Default is zabbix
::
2016-04-04 13:59:26 +02:00
Type: integer
2016-04-21 15:29:20 +02:00
Testparameters: /tmp /tmp/,root
2016-04-12 20:31:05 +02:00
Cache: 3600
2016-04-04 13:59:26 +02:00
Script::
2016-04-21 15:29:20 +02:00
case $who in
asroot|root)
2016-04-21 15:29:20 +02:00
! zaf_is_root && exec sudo -E -n $0 "$@";;
2016-04-12 20:31:05 +02:00
esac
2016-04-04 13:59:26 +02:00
2016-04-21 15:29:20 +02:00
du -sb "$path" | (read sum dir; echo $sum)
2016-04-04 13:59:26 +02:00
::
/Item:
2016-04-24 05:22:57 +02:00
Item items:
2016-04-04 13:59:26 +02:00
Description::
Number of items in discovered path (dirs+files+rest)
::
2016-04-21 15:29:20 +02:00
Parameters::
path '' '' # Path
who zabbix '^(root|zabbix)$' # which permissions to use. Sudo must be installed for root. Default is zabbix
::
2016-04-04 13:59:26 +02:00
Type: integer
2016-04-21 15:29:20 +02:00
Testparameters: /tmp /tmp/,root
2016-04-12 20:31:05 +02:00
Cache: 600
2016-04-04 13:59:26 +02:00
Script::
2016-04-21 15:29:20 +02:00
case $who in
asroot|root)
2016-04-21 15:29:20 +02:00
! zaf_is_root && exec sudo -E -n $0 "$@";;
2016-04-12 20:31:05 +02:00
esac
2016-04-04 13:59:26 +02:00
2016-04-21 15:29:20 +02:00
ls -1 "$path" |wc -l
2016-04-04 13:59:26 +02:00
::
/Item: