2016-04-04 13:59:26 +02:00
|
|
|
|
|
|
|
Plugin: fsx
|
|
|
|
Description::
|
|
|
|
Plugin which will make deeper look into directory structure using discovery
|
|
|
|
::
|
|
|
|
|
2016-04-15 08:03:50 +02:00
|
|
|
Version: 0.5
|
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
|
|
|
|
Sudo: /usr/bin/find %, {PLUGINDIR}/%sh %
|
|
|
|
|
|
|
|
# Cron for info about busy directories
|
|
|
|
# This is only example to get disk usage of common /var dirs
|
2016-04-14 10:00:20 +02:00
|
|
|
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::
|
2016-04-13 16:04:57 +02:00
|
|
|
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.
|
2016-04-04 13:59:26 +02:00
|
|
|
::
|
2016-04-13 16:04:57 +02:00
|
|
|
Parameters: {asroot|aszabbix} directory mask maxdepth type sort maxobjects
|
2016-04-04 13:59:26 +02:00
|
|
|
Type: string
|
2016-04-13 16:04:57 +02:00
|
|
|
Testparameters: aszabbix,/tmp/,%,10,d,name/+,0 aszabbix,/tmp/,%,10,d,du/+,10 asroot,/var/lib/dpkg/,%,1,d,name/-,10
|
2016-04-14 10:00:20 +02:00
|
|
|
Precache: asroot,/var/,%,100,d,du/-,100
|
|
|
|
Cache: 86400
|
2016-04-04 13:59:26 +02:00
|
|
|
Script::
|
|
|
|
#!/bin/sh
|
|
|
|
|
2016-04-12 20:31:05 +02:00
|
|
|
case $1 in
|
2016-04-13 16:04:57 +02:00
|
|
|
asroot|root)
|
2016-04-12 20:31:05 +02:00
|
|
|
shift; exec sudo -E -n $0 "$@";;
|
2016-04-13 16:04:57 +02:00
|
|
|
aszabbix|zabbix)
|
2016-04-12 20:31:05 +02:00
|
|
|
shift;;
|
|
|
|
esac
|
2016-04-04 13:59:26 +02:00
|
|
|
. $ZAF_LIB_DIR/preload.sh
|
2016-04-12 20:31:05 +02:00
|
|
|
|
2016-04-13 16:04:57 +02:00
|
|
|
[ "$#" -lt 6 ] && zaf_err "Bad parameters!"
|
2016-04-04 13:59:26 +02:00
|
|
|
dir="$1"
|
2016-04-04 14:48:57 +02:00
|
|
|
mask="-name '$(echo $2|tr '%' '*')'"
|
|
|
|
depth="-maxdepth $3"
|
2016-04-13 16:04:57 +02:00
|
|
|
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"
|
2016-04-04 13:59:26 +02:00
|
|
|
fi
|
|
|
|
|
2016-04-13 16:04:57 +02:00
|
|
|
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)
|
2016-04-14 10:00:20 +02:00
|
|
|
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}'
|
2016-04-13 16:04:57 +02:00
|
|
|
;;
|
|
|
|
esac
|
2016-04-04 13:59:26 +02:00
|
|
|
::
|
|
|
|
/Item
|
|
|
|
|
|
|
|
Item pathinfo_type:
|
|
|
|
Description::
|
|
|
|
Type of discovered path (d,f,l)
|
|
|
|
d - directory
|
|
|
|
f - file
|
|
|
|
l - symbolink link
|
|
|
|
::
|
2016-04-12 20:31:05 +02:00
|
|
|
Parameters: asroot discovered_path
|
2016-04-04 13:59:26 +02:00
|
|
|
Type: character
|
2016-04-13 16:04:57 +02:00
|
|
|
TestParameters: aszabbix,/tmp/
|
2016-04-04 13:59:26 +02:00
|
|
|
Script::
|
2016-04-12 20:31:05 +02:00
|
|
|
#!/bin/sh
|
2016-04-04 13:59:26 +02:00
|
|
|
|
2016-04-12 20:31:05 +02:00
|
|
|
case $1 in
|
2016-04-15 08:03:50 +02:00
|
|
|
asroot|root)
|
2016-04-12 20:31:05 +02:00
|
|
|
shift; exec sudo -E -n $0 "$@";;
|
2016-04-15 08:03:50 +02:00
|
|
|
aszabbix|zabbix)
|
2016-04-12 20:31:05 +02:00
|
|
|
shift;;
|
|
|
|
esac
|
2016-04-04 13:59:26 +02:00
|
|
|
. $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
|
|
|
|
::
|
2016-04-12 20:31:05 +02:00
|
|
|
Parameters: asroot discovered_path
|
2016-04-04 13:59:26 +02:00
|
|
|
Type: integer
|
2016-04-13 16:04:57 +02:00
|
|
|
TestParameters: aszabbix,/tmp/
|
2016-04-12 20:31:05 +02:00
|
|
|
Cache: 3600
|
2016-04-04 13:59:26 +02:00
|
|
|
Script::
|
2016-04-12 20:31:05 +02:00
|
|
|
#!/bin/sh
|
2016-04-04 13:59:26 +02:00
|
|
|
|
2016-04-12 20:31:05 +02:00
|
|
|
case $1 in
|
2016-04-15 08:03:50 +02:00
|
|
|
asroot|root)
|
2016-04-12 20:31:05 +02:00
|
|
|
shift; exec sudo -E -n $0 "$@";;
|
2016-04-15 08:03:50 +02:00
|
|
|
aszabbix|zabbix)
|
2016-04-12 20:31:05 +02:00
|
|
|
shift;;
|
|
|
|
esac
|
2016-04-04 13:59:26 +02:00
|
|
|
. $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)
|
|
|
|
::
|
2016-04-12 20:31:05 +02:00
|
|
|
Parameters: asroot discovered_path
|
2016-04-04 13:59:26 +02:00
|
|
|
Type: integer
|
2016-04-13 16:04:57 +02:00
|
|
|
TestParameters: aszabbix,/tmp/
|
2016-04-12 20:31:05 +02:00
|
|
|
Cache: 600
|
2016-04-04 13:59:26 +02:00
|
|
|
Script::
|
2016-04-12 20:31:05 +02:00
|
|
|
#!/bin/sh
|
2016-04-04 13:59:26 +02:00
|
|
|
|
2016-04-12 20:31:05 +02:00
|
|
|
case $1 in
|
2016-04-15 08:03:50 +02:00
|
|
|
asroot|root)
|
2016-04-12 20:31:05 +02:00
|
|
|
shift; exec sudo -E -n $0 "$@";;
|
2016-04-15 08:03:50 +02:00
|
|
|
aszabbix|zabbix)
|
2016-04-12 20:31:05 +02:00
|
|
|
shift;;
|
|
|
|
esac
|
2016-04-04 13:59:26 +02:00
|
|
|
. $ZAF_LIB_DIR/preload.sh
|
|
|
|
|
|
|
|
[ -z "$1" ] && zaf_err "Directory must be entered."
|
|
|
|
|
|
|
|
ls -1 "$1" |wc -l
|
|
|
|
::
|
|
|
|
/Item:
|
|
|
|
|
|
|
|
|