Nearly Full Disks
In this example, we report when file systems are near capacity.
The DiskCap script might send an alert message like the following:
PIKT ALERT
Thu Jun 14 07:52:39 2007
cadiz
EMERGENCY:
DiskCap
Report near-capacity filesystems
Filesystem /storage2 on /dev/hda3 is 96% full, 29807256 KB capacity, 1375492 Kb left
The =diskcap() script macro follows.
diskcap(LIMDEFAULT, LIMWARN, LIMURGENT, LIMEMERG, BYPASS)
init
status =piktstatus
level =piktlevel
task "Report near-capacity filesystems"
=dflinput
=dffilter
=dfdata
keys $fsname
begin
if $alert() =~~ "warning|notice|info"
// run this only on sundays
if ! =sunday
quit
fi
fi
rule
if $mount =~~ "^(BYPASS)$"
next
fi
rule
set $capmsg = "Filesystem $mount on $fsname is $text(100*#cap,0)% full,
$text(#kbytes) KB capacity, $text(#avail) Kb left"
rule // consider adding a =dutop(10, $mount) call in each case
if $alert() =~~ "emergency"
if #cap >= (LIMEMERG)
&& (! #defined(%cap) || (#cap > %cap))
output mail $capmsg
// =page()
fi
elsif $alert() =~~ "urgent"
if #cap >= (LIMURGENT)
&& (! #defined(%cap) || (#cap > %cap))
output mail $capmsg
fi
elsif $alert() =~~ "warning"
if #cap >= (LIMWARN)
&& (! #defined(%cap) || (#cap > %cap))
#if missioncritical
output mail $capmsg
#else
=output_other_mail(DISKCAP,
'PIKT Alert on =pikthostname: WARNING',
=piktadmin, $capmsg)
#endif
fi
else // for interactive, command-line scripts
if #cap >= (LIMDEFAULT)
// && (! #defined(%cap) || (#cap > %cap))
output $capmsg
fi
fi
end
quit
You would invoke this macro in your alarms.cfg (or one of its #include files) like so:
DiskCap
=diskcap(90%, 95%, 99%, 100%, )
This is just one program example. You could add rules, or write new scripts, for example to: report hardware failures, report network cross-mounted disks going off-line, report problems with the RAID setup, clear /tmp files, log I/O stats, etc.
For more examples, see Samples.