Plugin: fsx Description:: Plugin which will make deeper look into directory structure using discovery :: Version: 0.5 Url: https://raw.githubusercontent.com/limosek/zaf-plugins/master/fsx Web: https://github.com/limosek/zaf-plugins/ Maintainer: Lukas Macura # Dependencies Depends-dpkg: dash curl Depens-opkg: busybox curl Depends-rpm: curl Depends-bin: curl find # Sudo needed. It will be preconfigured if sudo is installed Sudo: /usr/bin/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. {asroot|aszabbix} - which permissions to use. Sudo must be installed for asroot directory - directory to scan mask - mask to search. Use % instead of * in mask. Like '%' to find all objects, '%.txt' to find all .txt files maxdepth - depth to search. 1 means only one directory, not subdirs type - Type of objects to find (f=file,d=dir,l=link) sort - how to sort results (name/[+-], du/[+-]) maxobjects - maximum objects to find. 0 means no limit. :: Parameters: {asroot|aszabbix} directory mask maxdepth type sort maxobjects Type: string Testparameters: aszabbix,/tmp/,%,10,d,name/+,0 aszabbix,/tmp/,%,10,d,du/+,10 asroot,/var/lib/dpkg/,%,1,d,name/-,10 Precache: asroot,/var/,%,100,d,du/-,100 Cache: 86400 Script:: #!/bin/sh case $1 in asroot|root) shift; exec sudo -E -n $0 "$@";; aszabbix|zabbix) shift;; esac . $ZAF_LIB_DIR/preload.sh [ "$#" -lt 6 ] && zaf_err "Bad parameters!" dir="$1" mask="-name '$(echo $2|tr '%' '*')'" depth="-maxdepth $3" type="-type $4" sort="$(echo $5|cut -d '/' -f 1)" sortorder="$(echo $5|cut -d '/' -f 2)" [ "$sortorder" = "-" ] && so="-r" maxobjects=$6 if [ "$maxobjects" -gt 0 ]; then head="head -n $maxobjects" else head="cat" fi case $sort in name) zaf_dbg find "$dir" $depth $type $mask \| sort $so \| $head \| zaf_discovery '{#PATH}' eval find "$dir" $depth $type $mask | sort $so | $head | zaf_discovery '{#PATH}' ;; du) zaf_dbg find "$dir" $depth $type $mask -print0 \| xargs -0 du \| sort -n $so \| $head \| zaf_discovery '{#PATH}' eval find "$dir" $depth $type $mask -print0 | xargs -0 du | sort -n $so | tr '\t' ' ' | cut -d ' ' -f 2 | $head |zaf_discovery '{#PATH}' ;; esac :: /Item Item pathinfo_type: Description:: Type of discovered path (d,f,l) d - directory f - file l - symbolink link :: Parameters: asroot discovered_path Type: character TestParameters: aszabbix,/tmp/ Script:: #!/bin/sh case $1 in asroot|root) shift; exec sudo -E -n $0 "$@";; aszabbix|zabbix) shift;; esac . $ZAF_LIB_DIR/preload.sh [ -z "$1" ] && zaf_err "Directory must be entered." [ -f "$1" ] && echo f && exit [ -d "$1" ] && echo d && exit [ -l "$1" ] && echo l && exit :: /Item: Item pathinfo_du: Description:: Disk usage of discovered path in bytes :: Parameters: asroot discovered_path Type: integer TestParameters: aszabbix,/tmp/ Cache: 3600 Script:: #!/bin/sh case $1 in asroot|root) shift; exec sudo -E -n $0 "$@";; aszabbix|zabbix) shift;; esac . $ZAF_LIB_DIR/preload.sh [ -z "$1" ] && zaf_err "Directory must be entered." du -sb "$1" | (read sum dir; echo $sum) :: /Item: Item pathinfo_items: Description:: Number of items in discovered path (dirs+files+rest) :: Parameters: asroot discovered_path Type: integer TestParameters: aszabbix,/tmp/ Cache: 600 Script:: #!/bin/sh case $1 in asroot|root) shift; exec sudo -E -n $0 "$@";; aszabbix|zabbix) shift;; esac . $ZAF_LIB_DIR/preload.sh [ -z "$1" ] && zaf_err "Directory must be entered." ls -1 "$1" |wc -l :: /Item: