fellow monks,
I just finished another of our custom nagios checks, which I all write after a similar fashion. I would like you to comment on this from a perspective of style vs. practicability.
This is the skeleton or boilerplate I normaly use:
#!/usr/bin/perl -T # creator : Tom Regner <mail@address.tld> # created : Wed 11 Jun 2003 05:10:32 PM CEST # version : $Id: check_ifconfig,v 1.1 2003/06/12 13:17:35 tom Exp $ # copyright : (c) 2003 my company # use strict; use warnings; use Getopt::Long; use vars qw($opt_V $opt_h @opt_i @opt_n $PROGNAME $VERSION); use lib "/data/programme/nagios/libexec" ; use utils qw(%ERRORS &print_revision &support &usage &exit_); $PROGNAME = "progname"; #$VERSION = '$Revision'; # as originally posted $VERSION = '$Revision$'; # Update sub print_help (); sub print_usage (); $ENV{'PATH'}=''; $ENV{'BASH_ENV'}=''; $ENV{'ENV'}=''; Getopt::Long::Configure('bundling'); GetOptions ( "V" => \$opt_V, "version" => \$opt_V, "h" => \$opt_h, "help" => \$opt_h, ); if ($opt_V) { print_revision($PROGNAME,$VERSION); exit($ERRORS{'OK'}) ; } if ($opt_h) {print_help(); exit($ERRORS{'OK'});} # # main-test # # untaint args # check correctness of args my $msg = ''; # return message my $status = $ERRORS{OK}; # exit status # # perform test # exit_($status, $msg); # # subs for test-parts, recurring actions during the test, etc. # sub check { my ($stuff1, $stuff2,) = @_; my ($result, $dmsg) = (1, ""); # # do test, in case of error, change global variable $status # # assamble info into $dmsg # $msg .= $dmsg; # $msg is 'global' return $result; } # # nagios plugin-standards # sub print_usage () { } sub print_help () { print_revision($PROGNAME,$VERSION); print_usage(); support(); }
The test-logic is under 30 lines of code (including the subs) most of the time.
Is this bad style in your opinion? What would you change? How do you write your nagios-checks?
kind regards,
tomte
Hlade's Law:
If you have a difficult task, give it to a lazy person --
they will find an easier way to do it.
Update per author's request - dvergin 2003-06-13
In reply to 'global' variables in small scripts -- a question of style? by Tomte
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |