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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.