[Nagiosplug-devel] New function for N::P

Thomas Guyot-Sionnest dermoth at aei.ca
Wed Sep 19 09:46:04 CEST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'd like to add a new function (max_state) to N::P but I never played
with perl libs, so I'll let it to more experienced programmers.

According to the way max_state is written in C (plus the fix I suggested
in the other thread), the code should look like this:

sub max_state {
  my $ret = shift;
  while (defined(my $state = shift)) {
    if ($state == CRITICAL) {
      $ret = CRITICAL;
    } elsif ($state == WARNING && $ret != CRITICAL) {
      $ret = WARNING;
    } elsif ($state == UNKNOWN && $ret != CRITICAL && $ret != WARNING) {
      $ret = UNKNOWN;
    } elsif ($state == DEPENDENT && $ret != CRITICAL && $ret != WARNING
&& $ret != UNKNOWN) {
      $ret = DEPENDENT;
    } elsif ($state > DEPENDENT) {
      $ret = $state if ($state > $ret );
    }
  }
  return $ret;
}

Contradictory to its C counterpart, this one can accept more than two
values.



For the doc, I guess it should go to the exit methods section:

=item max_state( $result1, $result2, ...)

Return the most critical state. The order is CRITICAL, WARNING, UNKNOWN,
DEPENDENT then the highest non-0 result. It returns OK only if all
parameters are OK.


And an example for the synopsis:

$ret = max_state($result1, $result2);

Thomas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG8NO86dZ+Kt5BchYRAqExAKC/TIeHRNPLxPmXw0fJMe16jfcNigCguaDc
Kj2IEp2f1Pmd+leh81eDqDk=
=1SWt
-----END PGP SIGNATURE-----




More information about the Devel mailing list