1
0
mirror of https://github.com/limosek/zaf-plugins.git synced 2024-11-01 08:17:19 +01:00
limosek-zaf-plugins/fsx/control.zaf
2016-04-13 16:04:57 +02:00

163 lines
3.7 KiB
Plaintext

Plugin: fsx
Description::
Plugin which will make deeper look into directory structure using discovery
::
Version: 0.3
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
# 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 * * * * (zabbix zaf precache 'fsx.pathinfo_du[asroot,/var/]' && zaf precache 'fsx.pathinfo_du[asroot,/var/mail]' && zaf precache 'fsx.pathinfo_du[asroot,/var/lib]') >/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: aszabbix,/tmp/,%,10,d,name/+,0 asroot,/var/,%,100,d,du/-,100
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
[ "$#" -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 \| xargs du \| sort -n $so \| $head \| zaf_discovery '{#PATH}'
eval find "$dir" $depth $type $mask | xargs 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)
shift; exec sudo -E -n $0 "$@";;
aszabbix)
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)
shift; exec sudo -E -n $0 "$@";;
aszabbix)
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)
shift; exec sudo -E -n $0 "$@";;
aszabbix)
shift;;
esac
. $ZAF_LIB_DIR/preload.sh
[ -z "$1" ] && zaf_err "Directory must be entered."
ls -1 "$1" |wc -l
::
/Item: