[Nagiosplug-devel] check_maxchannels for perl framework

Howard Wilkinson howard at cohtech.com
Wed Mar 31 00:43:18 CEST 2004


Stanley,

I intend to produce a design/suage document shortly. It will be small 
with dot points if I can get it out shortly. The rational for this 
approach is 2 fold. Adding the burden to the plugin writer to produce 
the output of the usage, help, version and other standard function in a 
consistent and complete fashion seems to me to be unnecessary which has 
led to the thinking that perhaps a framework for the entire operation of 
a plugin would be a good idea, which has led to this approach being 
adopted. The second is the thing that got me started on all of this, 
which was needing to get consistent, complet and upto date usage 
information and help information in machine processable form for entry 
into a database. This database is then used to provide a user interface 
that can prompt for data from the user when building Nagios 
configurations. I need to be able to do type checking, provide value 
checks where possible, confirm that parameters will be compatible (e.g. 
SNMPv1 with SNMPv3 authorisation arguments do not make much sense) and 
so on.

Thus, I am led to the approach shown in the Plugin and Plugin::Parameter 
modules. Probably coudl be done better, could certainly use Perl smarter 
and give more consise files (but probably not faster executing) but it 
does have some industrial strength and will if finished provide a much 
easier environment within which plugins of greater content can be 
written. I am working on standardising the SNMP framework to allow the 
writer to concentrate on processing the MIB results, as well as, 
providing a common error reporting framework and output production 
framework.

On a note I received from Karl and have responded to but is related to 
peerformance. Our exeperience so far is that this has little eimpact on 
a running monitor environment, where about 50% of our plugin executions 
have now been changed to operate this. The cost of loading the Plugin 
could be reduced considerabley if the POD is removed from the Plugin.pm 
and Plugin::Parameter.pm files - this could be done at compile time by 
fixing the Makefile. This would reduce the file size by > 50% thus the 
overhead is about 35K source code. Further pounding on my style could 
easily bring this down by 50% so for smaller machines we could make this 
a not problem.

I have not tested under ePN although I believe I have stuck to the rules 
for compile once, run many operation. I would appreciate some live 
running under ePN by someone and some feedback on what to fix, as we 
will be implementign an ePN based environment later this year and I 
would like to concentrate on getting working and not the plugin's.

Another note. All of the plugins now have taint checking on by default, 
and have been fixed to work in this environment.

Regards, Howard.

Stanley Hopcroft wrote:

>Dear Sir,
>
>I am writing to thank you for your 'small patches' and compliment you on 
>your prolificity.
>
>Well done !
>
>Please would you consider a group posting of
>
>. your rationale (small dot points for me please) for this approach
>
>  - eg facilitate plugin integration in GUI config manager ?
>
>. the performance impact of the new framework (/usr/bin/time repeatd a 
>few times [vi] of the original plugin and that in the framework)
>
>. how it performs under ePN - can't imagine it's a problem and I will 
>  probably try this.
>
>I like the 'opt in' approach to option checking; that alone should make 
>a plugin authors lot a much easier one.
>
>Yours sincerely.
>
>--
>------------------------------------------------------------------------
>Stanley Hopcroft
>------------------------------------------------------------------------
>
>'...No man is an island, entire of itself; every man is a piece of the
>continent, a part of the main. If a clod be washed away by the sea,
>Europe is the less, as well as if a promontory were, as well as if a
>manor of thy friend's or of thine own were. Any man's death diminishes
>me, because I am involved in mankind; and therefore never send to know
>for whom the bell tolls; it tolls for thee...'
>
>from Meditation 17, J Donne.
>  
>
>------------------------------------------------------------------------
>
>#!/usr/bin/perl -w
>
>use strict ;
>
>#
>#
>#	dotime
>#
>#	L Wall, "Programming Perl 1st ed" p 331
>#
>#	usage dotime repeat command
>
># 	updated for P 5 by S Hopcroft
>
>
>die "Usage: dotime <repeat> <command>\n" if @ARGV < 2 ;
>
>my $repeat = shift(@ARGV) ;
>die "Invalid repeat: $repeat, stopped" 
>  unless (($repeat > 0) && ($repeat < 999)) ;
>
>use vars qw($arg) ;
>
>my $times = ($repeat == 1 ? "once" : "$repeat times") ;
>print qq/Running @ARGV $times\n/ ;
>$| = 1 ;
>
>my %run_time = (  real => { total => 0, list => [] },
>	          user => { total => 0, list => [] },
>	          sys  => { total => 0, list => [] }
>	       ) ;
>
>for my $pass (1 .. $repeat) {
>  print "$pass " ;
>  open (TIMES, "/usr/bin/time @ARGV 2>&1 |") 
>    || die "Can't run /usr/bin/time @ARGV 2>&1, stopped" ;
>  while (<TIMES>) {
>    my %t ;
>    if ( @t{ qw(real user sys) } = /^\s*(\S+) real\s*(\S+) user\s*(\S+) sys/ ) {
>      foreach my $time ( keys %run_time ) {
>        $run_time{$time}{total} +=        $t{$time} ;
>        push @{ $run_time{$time}{list} }, $t{$time} ;
>      }
>    }
>  }
>  close (TIMES) ;
>}
>
>print "done\n" ;
>
>my $fields_per_line = 15 ;
>my ($fields, $values, $avg, $form) ;
>
>$form = "format STDOUT =\n" ;
>
>if ( $repeat <= $fields_per_line) {
>
>  $fields = '@<<<<@>>>>>>' . '@>>>>>>>>' x $repeat ;
>  $values = '$arg,$avg   ' . ',shift @_' x $repeat ;
>  $form .=<<EOF ;
>$fields
>$values
>.
>EOF
>
>} else {
>
>  # XXXX
>  # The values must follow the picture lines.
>  # So they must be wrapped also (otherwise a SEGV from the write statement).
>  # XXXX
>
>  my $data_fields = $fields_per_line - 2 ;
>  #  Only $fields_per_line - 2 datum are displayed on each line of output
>
>  my $spaces = ' ' x 12 ;
>
>  # the multiple of ' ' is the number of chars used by the $arg and $avg fields in the first line 
>  # PLUS the number 2 (for the '@' field markers) so that the fields line up for debugging.
>
>  my $fields = '@<<<<@>>>>>>' . '@>>>>>>>>' x $data_fields ;
>  my $values = '$arg,$avg  ' . ',shift @_'  x $data_fields ;
>
>  $form .=<<EOF ;
>$fields
>$values
>EOF
>
>  my $line_pics = $spaces . '@>>>>>>>>' x $data_fields ;
>  my $line_vals = $spaces . ',shift @_' x $data_fields ;
>
>  my $lines_remaining = int( ($repeat - $data_fields)/$data_fields )  ;
>
>  $form .=<<EOF x $lines_remaining ;
>$line_pics
>$line_vals
>EOF
>
>  my $fields_remaining = ($repeat - $data_fields) % $data_fields ;
>  $fields = ( $fields_remaining ? $spaces . '@>>>>>>>>' x $fields_remaining : "\n" ) ;
>  $values = ( $fields_remaining ? $spaces . ',shift @_' x $fields_remaining : "\n" ) ;
>
>  $form .=<<EOF ;
>$fields
>$values
>.
>EOF
>
>}
>
># XXXX
>
>$arg = ' ' ;
>
># $arg __cannot__ be a lexical or its value is not displayed.
># XXXX
>
>eval $form ;
>
>sub write {
>  $avg = shift ;
>  write ;
>}
>
>&write('Avg', 1 .. $repeat) ;
>
>&write(split(' ', ' ------' x ($repeat + 1))) ;
>
>foreach $arg ( qw(real user sys) ) {
>  &write( sprintf("%6.3f", $run_time{$arg}{total}/$repeat),
>          @{ $run_time{$arg}{list} }
>        ) ;
>}
>  
>

-- 
Howard Wilkinson
	Phone:
	+44(20)7690 7075
Coherent Technology Limited
	Fax:
	+44(20)79230110
33 Belgrade Road, Stoke Newington,
	Mobile:
	+44(7980)639379
London, United Kingdom, N16 8DH
	Email:
	<mailto:howard at cohtech.com>howard at cohtech.com




This message contains confidential information and is intended only
for the individual named. If you are not the named addressee you
should not disseminate, distribute or copy this e-mail. Please
notify the sender immediately by e-mail if you have received this
e-mail by mistake and delete this e-mail from you system.

E-mail transmission cannot be guarenteed to be secure or error-free
as information could be intercepted, corrupted, lost, destroyed,
arrive late or incomplete, or contain viruses. The sender therefore
does not accept liability for any errors or omissions in the contents
of this message which arise as a result of e-mail transmission. If
verification is required please request a hard-copy version.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-plugins.org/archive/devel/attachments/20040331/30c33b31/attachment.html>


More information about the Devel mailing list