Ok well in case anyone else is wondering, here's the solution I came up with:<br><br><span style="font-family: courier new,monospace;"># cat /usr/local/nagios/libexec/check_io.pl</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#!/usr/bin/perl</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"># author: alex harvey</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"># email: <a href="mailto:alexh19740110@gmail.com">alexh19740110@gmail.com</a></span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"># definitions</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">use constant OK => 0;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">use constant WARNING => 1;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">use constant CRITICAL => 2;</span>
<br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"># read in config file</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">require "/usr/local/nagios/etc/check_io.cfg";</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
# main</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">open IOSTAT, "$IOSTAT $INTERVAL 3 | $TAIL -${LINES} |";</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">while ( <IOSTAT> ) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> @col = split ' ';</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> foreach $disk (keys %DISKS) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> if ( $disk eq $col[0] ) {</span>
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> if ( $col[0] eq $disk ) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
$DISKS{$disk}[0] = $col[1];</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $DISKS{$disk}[1] = $col[2];</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> $DISKS{$disk}[2] = $col[7];</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $DISKS{$disk}[3] = $col[9];
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">}</span>
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">close IOSTAT;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">$exit_state = OK;
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">foreach $disk (sort (keys %DISKS)) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
if ( $DISKS{$disk}[2] >= $SVC_T_WTHRESHOLD && $DISKS{$disk}[3] >= $PC_B_WTHRESHOLD )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> if ( $DISKS{$disk}[2] < $SVC_T_CTHRESHOLD && $DISKS{$disk}[3] < $PC_B_WTHRESHOLD )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
{</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $exit_state = ($exit_state < CRITICAL) ? WARNING : $exit_state;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> } else {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $exit_state = CRITICAL;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> $exit_message = $exit_message.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> " ".$disk.</span>
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ":: [ r/s: ".$DISKS{$disk}[0].</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
", w/s: ".$DISKS{$disk}[1].</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ", svc_t: ".$DISKS{$disk}[2].</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> ", and %b: ".$DISKS{$disk}[3].</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> " ],";
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">if ( $exit_state == OK ) {
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $exit_message = "OK -$exit_message";</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
} elsif ( $exit_state == WARNING ) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $exit_message = "WARNING -$exit_message";</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">} else {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $exit_message = "CRITICAL -$exit_message";</span>
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">$exit_message =~ s/,$/\n/;
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">print $exit_message;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
exit $exit_state</span><br style="font-family: courier new,monospace;"><br>And the configuration file:<br><br><span style="font-family: courier new,monospace;"># cat /usr/local/nagios/etc/check_io.cfg</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"># check_io.cfg</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"># constants
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">$DISKS = 3; # number of physical disk partitions</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"># diskid => [ r/s, w/s, service_time, %busy ]</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">%DISKS = (</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> sd0 => [ 0, 0, 0, 0 ],</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> sd1 => [ 0, 0, 0, 0 ],</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> sd6 => [ 0, 0, 0, 0 ]</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">);</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">$IOSTAT = '/usr/bin/iostat -x';</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">$TAIL = '/usr/bin/tail';</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
$LINES = 7; # number of lines in iostat -x</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">$INTERVAL = 5; # second interval for iostat</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">$SVC_T_WTHRESHOLD = 30;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
$PC_B_WTHRESHOLD = 5;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">$SVC_T_CTHRESHOLD = 40;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
$PC_B_CTHRESHOLD = 10;</span><br style="font-family: courier new,monospace;"><br>This is for a Solaris box whose iostat output looks like this:<br><br><span style="font-family: courier new,monospace;"># iostat -x</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> extended device statistics</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">device r/s w/s kr/s kw/s wait actv svc_t %w %b
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">sd0 0.0 1.4 0.3 9.4 0.0 0.0 31.6 0 1</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">sd1 0.0 0.0 0.0 0.0 0.0 0.0 3.4 0 0</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">sd6
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">st12 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0</span>
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">nfs1 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0</span><br style="font-family: courier new,monospace;"><br>Regards,
<br>Alex<br style="font-family: courier new,monospace;"><br><br><div><span class="gmail_quote">On 10/17/06, <b class="gmail_sendername">Andreas Ericsson</b> <<a href="mailto:ae@op5.se">ae@op5.se</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Alexander Harvey wrote:<br>> That doesn't look like a Solaris script to me but as far as your coding is<br>> concerned, my thoughts are<br>><br><br>[ excellent and non-disputed points removed ]<br><br>> (iv) for security you ought to use full paths to all of your binaries:
<br>> i.e.<br>> /usr/bin/echo<br>> instead of<br>> echo<br>><br><br>"echo" is a built-in feature of pretty much all shells, so just using<br>plain 'echo' is a perfectly viable and more performance friendly option.
<br><br>A better solution, for security's sake, is to force the $PATH to a safe<br>value at the beginning of the script and not bother with full paths.<br><br>As a last note, "echo" is required to exist on the root partition, which
<br>places it in /bin on all systems I've ever come across.<br><br>--<br>Andreas Ericsson <a href="mailto:andreas.ericsson@op5.se">andreas.ericsson@op5.se</a><br>OP5 AB <a href="http://www.op5.se">
www.op5.se</a><br>Tel: +46 8-230225 Fax: +46 8-230231<br></blockquote></div><br>