Add a ZFS plugin (both config file and script)

In order to check ZFS pool health.
This commit is contained in:
Jeremy Gardais 2018-06-22 16:04:32 +02:00
parent 2564ddb065
commit ebce8bc85f
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
6 changed files with 165 additions and 2 deletions

View File

@ -7,6 +7,7 @@
* Ensure to apply the config only if wanted.
* Some yamllint fix.
* Add a all hosts variable for the plugin "list" whitelist.
* Add a ZFS plugin (both config file and script).
## v1.1

View File

@ -43,6 +43,11 @@ Manage Xymon (client) installation and configuration.
* **xymon_plug_libs_whitelist**: All hosts whitelist of processes that should not be monitored with `libs` plugin.
* **xymon_plug_libs_group_whitelist**: Group whitelist of processes that should not be monitored with `libs` plugin.
* **xymon_plug_libs_host_whitelist**: Host whitelist of processes that should not be monitored with `libs` plugin.
* **xymon_cli__plug_zfs_state**: The state of plugin `zfs` [default: `false`].
* **xymon_cli__plug_zfs_script_path**: Path to the ZFS script [default: `/usr/lib/xymon/client/ext/zfs`].
* **xymon_cli__plug_zfs_script_tpl**: Template used to generate the previous script [default: `usr/lib/xymon/client/ext/zfs.j2`].
* **xymon_cli__plug_zfs_path**: Configuration file for the `zfs` plugin [default: `/etc/xymon/clientlaunch.d/zfs.cfg`].
* **xymon_cli__plug_zfs_tpl**: Template used to generate the previous config file [default: `etc/xymon/clientlaunch.d/zfs.cfg.j2`].
### OS Specific Variables
@ -73,6 +78,7 @@ Some plugins and options can be managed with this role:
* apt: Check state of packages and repositories.
* libs: Check for running processes with upgraded libraries.
* mq: Check mail queue.
* zfs: Check ZFS pools status.
## Development

View File

@ -46,7 +46,6 @@ xymon_srv_list: "monitoring.{{ ansible_domain }}"
# Plugins management [[[
# ----------------------
# plugins [[[
xymon_plug_manage: true
## Plugin apt [[[
@ -80,7 +79,14 @@ xymon_plug_libs_whitelist: {}
xymon_plug_libs_group_whitelist: {}
xymon_plug_libs_host_whitelist: {}
## ]]]
# ]]]
## Plugin zfs [[[
xymon_cli__plug_zfs_state: false
xymon_cli__plug_zfs_script_path: '/usr/lib/xymon/client/ext/zfs'
xymon_cli__plug_zfs_script_tpl: 'usr/lib/xymon/client/ext/zfs.j2'
xymon_cli__plug_zfs_path: '/etc/xymon/clientlaunch.d/zfs.cfg'
xymon_cli__plug_zfs_tpl: 'etc/xymon/clientlaunch.d/zfs.cfg.j2'
# ]]]
# ]]]

View File

@ -125,3 +125,24 @@
xymon_plug_manage|bool)
notify: restart xymon-client service
# Manage zfs plugin [[[1
- name: PLUGIN zfs config file
template:
src: '{{ xymon_cli__plug_zfs_tpl }}'
dest: '{{ xymon_cli__plug_zfs_path }}'
owner: root
group: root
mode: 0644
when: (xymon_cli_manage|bool and
xymon_plug_manage|bool)
notify: restart xymon-client service
- name: PLUGIN zfs script file
template:
src: '{{ xymon_cli__plug_zfs_script_tpl }}'
dest: '{{ xymon_cli__plug_zfs_script_path }}'
owner: root
group: xymon
mode: 0755
when: (xymon_cli_manage|bool and
xymon_plug_manage|bool)

View File

@ -0,0 +1,6 @@
[zfs]
{{ '#DISABLED' if xymon_cli__plug_zfs_state else 'DISABLED' }}
ENVFILE /etc/xymon/xymonclient.cfg
CMD /usr/bin/sudo -E -u root $XYMONCLIENTHOME/ext/zfs
LOGFILE /var/log/xymon/zfs.log
INTERVAL 5m

View File

@ -0,0 +1,123 @@
#!/bin/ksh
# Revision History:
# 1. Mike Rowell <Mike.Rowell@Rightmove.co.uk>, original
# 2. Uwe Kirbach <U.Kirbach@EnBW.com>
# 3. T.J. Yang: add in some comments.
# 4. Vernon Everett <everett.vernon@gmail.com : Added check for old snapshots
# : Added graphing data
# 5. Pierre ROLLAND : Fixing column parsing when using the command zpool list -H
DISKYELL=80
DISKRED=90
SNAPRED=90 # Days old
SNAPYELL=60 # Days old
SNAPCOL=true # Set to true if snapshot age should effect test colour
CHECKSNAPS=true # Set to true to do snapshot checking
TEST="zfs"
DISPCOLOR="green"
FIRST_LINE="zfs - okay"
FIRST_LINE_HEALTH="okay"
FIRST_LINE_CAP="okay"
DATA=""
#What: beautify the page display by html code.
STRING="<table border=1 cellpadding=10><tr><th></th><th>Zpool Name</th><th>Status</th><th>Capacity</th></tr>"
#What: a loop to parse output of "zpool list -H" output.
# bash-3.00# zpool list
# NAME SIZE USED AVAIL CAP HEALTH ALTROOT
# mypool 33.8G 84.5K 33.7G 0% ONLINE -
# bash-3.00# zpool list -H
# mypool 33.8G 84.5K 33.7G 0% ONLINE -
# bash-3.00#
if [ ! -f /sbin/zpool ]; then
exit 0
fi
#/sbin/zpool list -H | while read name size used avail cap health altroot
/sbin/zpool list -H | while read name size used avail expandsz frag cap dedup health altroot
do
LINE_COLOR="green"
if [ "${health}" == "ONLINE" ]; then
HEALTH_COLOR="green"
elif [ "${health}" == "DEGRADED" ]; then
HEALTH_COLOR="yellow"
elif [ "${health}" == "FAULTED" ]; then
HEALTH_COLOR="red"
fi
CAP_COLOR="green"
cap=`echo ${cap} | cut -d% -f1`
if [ "${cap}" -ge $DISKYELL ]; then
CAP_COLOR="yellow"
elif [ "${cap}" -gt $DISKRED ]; then
CAP_COLOR="red"
fi
DATA=$(echo "$name : $cap\n$DATA")
# Determine the line colours
[ "$HEALTH_COLOR" == "yellow" -o "$CAP_COLOR" == "yellow" ] && LINE_COLOR="yellow"
[ "$HEALTH_COLOR" == "red" -o "$CAP_COLOR" == "red" ] && LINE_COLOR="red"
# Determine the messages
[ "$HEALTH_COLOR" == "yellow" -a "$FIRST_LINE_HEALTH" != "faulted" ] && FIRST_LINE_HEALTH="degraded"
[ "$HEALTH_COLOR" == "red" ] && FIRST_LINE_HEALTH="faulted"
[ "$CAP_COLOR" == "yellow" -a "$FIRST_LINE_CAP" != "full" ] && FIRST_LINE_CAP="nearly full"
[ "$CAP_COLOR" = "yellow" ] && FIRST_LINE_CAP="full"
#Determine the final colour status
[ "$LINE_COLOR" == "yellow" -a "$DISPCOLOR" != "red" ] && DISPCOLOR="yellow"
[ "$LINE_COLOR" == "red" ] && DISPCOLOR="red"
STRING="$STRING <tr><td>&${LINE_COLOR}</td><td>${name}</td><td>${health}</td><td>${cap} %</td></tr>"
done
DATA=$(echo "$DATA \n\n")
STRING="$STRING </table><br><br>"
STRING="$STRING`/sbin/zpool status -xv`"
FIRST_LINE="zfs - health: $FIRST_LINE_HEALTH - capacity: $FIRST_LINE_CAP"
# Snapshot check
if [ "$CHECKSNAPS" = "true" ]
then
NOW=$(perl -e 'print time(), "\n" ')
SNAPLIST=$(zfs list | grep @ |awk '{ print $1 }' \
| while read a
do
echo "$(zfs get -H -o name,value -p creation $a) $( zfs get -H -o value used $a)"
done)
if [ -z "$SNAPLIST" ]
then
SNAPTABLE="<br>&green No snapshots found"
else
SNAPTABLE="<table border=1 cellpadding=10><tr><th></th><th>Snapshot</th><th>Age</th><th>Size</th></tr>"
echo "$SNAPLIST" | while read SNAPSHOT CREATION SIZE
do
LINE_COLOR=green
((SNAPREDS=SNAPRED*43200))
((SNAPYELLS=SNAPYELL*43200))
((AGES=NOW-CREATION)) # AGES=Age in seconds
[ $AGES -gt $SNAPYELLS ] && LINE_COLOR=yellow
[ $AGES -gt $SNAPREDS ] && LINE_COLOR=red
[ $AGES -gt 120 ] && ((AGE=AGES/60))&& AGE="$AGE Minutes"
[ $AGES -gt 7200 ] && ((AGE=AGES/3600)) && AGE="$AGE Hours"
[ $AGES -gt 172800 ] && ((AGE=AGES/86400)) && AGE="$AGE Days"
SNAPTABLE="$SNAPTABLE <tr><td>&${LINE_COLOR}</td><td>${SNAPSHOT}</td><td>${AGE}</td><td>${SIZE}</td></tr>"
if [ "$SNAPCOL" = "true" ] #Only if true will it effect test colour
then
if [ "$DISPCOLOR" != "red" ] # If it's already red, it's not getting any worse
then
[ "$LINE_COLOR" != "green" ] && DISPCOLOR=$LINE_COLOR
fi
fi
done
SNAPTABLE="$SNAPTABLE </table><br><br>"
fi
STRING="$STRING <br><br><B>SNAPSHOT STATUS</B> $SNAPTABLE"
fi
# What: Sent out the final bb message to hobbit server.
$XYMON $XYMONSRV $XYMONSERVERS "status $MACHINE.$TEST $DISPCOLOR `date` $FIRST_LINE $STRING"
echo "$XYMON $XYMONSRV $XYMONSERVERS --debug status $MACHINE.$TEST $DISPCOLOR `date` $FIRST_LINE $STRING" > /tmp/xymon_zfs
$XYMON $XYMONSRV $XYMONSERVERS "data $MACHINE.$TEST $DISPCOLOR $(echo; echo "$DATA" ;echo;echo)"