mirror of
https://github.com/limosek/zaf-plugins.git
synced 2024-11-01 08:17:19 +01:00
157 lines
3.8 KiB
Plaintext
157 lines
3.8 KiB
Plaintext
|
|
Plugin: fsx
|
|
Description::
|
|
Plugin which will make deeper look into directory structure using discovery
|
|
::
|
|
|
|
Version: 0.8
|
|
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
|
|
Depends-opkg: busybox curl
|
|
Depends-rpm: curl
|
|
Depends-bin: curl find
|
|
|
|
# Sudo needed. It will be preconfigured if sudo is installed
|
|
Sudo: find %, {PLUGINDIR}/%sh %
|
|
|
|
# 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
|
|
::
|
|
|
|
Item discovery:
|
|
Description::
|
|
Discovery of files or directories.
|
|
::
|
|
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
|
|
::
|
|
Type: string
|
|
Testparameters: /tmp/ /tmp/,%,f,1,name/+,10,root
|
|
Precache: /tmp/
|
|
Cache: 86400
|
|
Script::
|
|
|
|
case $who in
|
|
asroot|root)
|
|
! zaf_is_root && exec sudo -E -n $0 "$@";;
|
|
esac
|
|
|
|
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"
|
|
|
|
if [ "$maxobjects" -gt 0 ]; then
|
|
head="head -n $maxobjects"
|
|
else
|
|
head="cat"
|
|
fi
|
|
|
|
tmpf=$ZAF_TMP_DIR/fsx$$
|
|
case $sorttype in
|
|
name)
|
|
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)
|
|
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
|
|
rm -f $tmpf
|
|
::
|
|
/Item
|
|
|
|
Item type:
|
|
Description::
|
|
Type of discovered path (d,f,l)
|
|
d - directory
|
|
f - file
|
|
l - symbolink link
|
|
::
|
|
Parameters::
|
|
path '' '' # Path
|
|
who zabbix '^(root|zabbix)$' # which permissions to use. Sudo must be installed for root. Default is zabbix
|
|
::
|
|
Type: character
|
|
Testparameters: /tmp/ /tmp/,root
|
|
Script::
|
|
|
|
case $who in
|
|
asroot|root)
|
|
! zaf_is_root && exec sudo -E -n $0 "$@";;
|
|
esac
|
|
|
|
[ -f "$path" ] && echo f && exit
|
|
[ -d "$path" ] && echo d && exit
|
|
[ -l "$path" ] && echo l && exit
|
|
::
|
|
/Item:
|
|
|
|
Item du:
|
|
Description::
|
|
Disk usage of discovered path in bytes
|
|
::
|
|
Parameters::
|
|
path '' '' # Path
|
|
who zabbix '^(root|zabbix)$' # which permissions to use. Sudo must be installed for root. Default is zabbix
|
|
::
|
|
Type: integer
|
|
Testparameters: /tmp /tmp/,root
|
|
Cache: 3600
|
|
Script::
|
|
|
|
case $who in
|
|
asroot|root)
|
|
! zaf_is_root && exec sudo -E -n $0 "$@";;
|
|
esac
|
|
|
|
du -sb "$path" | (read sum dir; echo $sum)
|
|
::
|
|
/Item:
|
|
|
|
Item items:
|
|
Description::
|
|
Number of items in discovered path (dirs+files+rest)
|
|
::
|
|
Parameters::
|
|
path '' '' # Path
|
|
who zabbix '^(root|zabbix)$' # which permissions to use. Sudo must be installed for root. Default is zabbix
|
|
::
|
|
Type: integer
|
|
Testparameters: /tmp /tmp/,root
|
|
Cache: 600
|
|
Script::
|
|
|
|
case $who in
|
|
asroot|root)
|
|
! zaf_is_root && exec sudo -E -n $0 "$@";;
|
|
esac
|
|
|
|
ls -1 "$path" |wc -l
|
|
::
|
|
/Item:
|
|
|
|
|