Bonjour,

Je mets à disposition un petit script Perl pour la supervision d'OBM-Sync par 
Nagios.
Il faut le mettre dans le répertoire des plugins Nagios.
Il faut adapter la ligne suivante au début du fichier :

use lib "/usr/lib64/nagios/plugins/";

Pour lui indiquer ou il trouvera le fichier "utils.pm",  qui est normallement 
avec les plugins Nagios.
Pour les dépendances, sous redhat et centos, il faut installer :

perl-XML-LibXML
perl-libwww-perl

Pour une utilisation en ligne de commande, il suffit de faire un :

/usr/lib64/nagios/check_obm-sync.pl   --hostname obm-adresse.fr --ssl  --url 
/obm-sync/services  --login compte.test  --passwd "motdepasse"

pour avoir des infos sur les arguments possibles :

/usr/lib64/nagios/check_obm-sync.pl --help


Pour une utilisation dans Nagios ou Centreon, voici ce que j'utilise pour la 
ligne de commande :

$USER1$/check_obm-sync.pl --hostname $HOSTADDRESS$ --ssl --url $ARG1$ --login 
$ARG2$ --passwd $ARG3$

et pour les arguments du service :

!/obm-sync/services!compte.test!motdepasse


je suis preneur bien entendu de toute critique ou amélioration de ce script.



#!/usr/bin/perl -w

use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use XML::LibXML;
use Getopt::Long;

#use lib "/usr/lib/nagios/plugins/";
use lib "/usr/lib64/nagios/plugins/";
use utils qw(%ERRORS $TIMEOUT &print_revision);
use strict;

# globals
use vars qw(
  $PROGNAME $VERSION $opt_version $opt_help $opt_host $opt_url $opt_ssl $opt_login $opt_passwd );

# init options

$PROGNAME       = 'check_obm-sync.pl';
$VERSION        = '0.1';
$opt_version    = undef;
$opt_help       = undef;
$TIMEOUT        = 20;
$opt_host       = undef;
$opt_url        = undef;
$opt_ssl        = undef;
$opt_login      = undef;
$opt_passwd     = undef;

sub print_usage {
  my $tab = ' ' x length($PROGNAME);
  print <<EOB
Usage:
 $PROGNAME  -H=<host> -l=login -p=password [ -t=timeout ]
 $PROGNAME --version
 $PROGNAME --help
EOB
}

sub print_version {
  print_revision($PROGNAME, $VERSION);
}

sub print_help {
  print_version();
  print <<EOB;

OBM-Sync Monitor for Nagios

EOB

  print_usage();
  print <<EOB;

Required Arguments:
-h, --help
        print this message
-H, --hostname=HOST
        name or IP of host to check
-u, --url=URL
        location of the service
-s, --ssl
        activate the SSL protocol (https://)
-l, --login=LOGIN
        Login  for authentication
-p, --passwd=PASSWORD
        Password for OBM-Sync authentication
-t, --timeout=INTEGER
        Timeout in seconds (Default: $TIMEOUT)
-V, --version
        prints version in number

Example: check_obm-sync.pl --hostname=obm.inserm.fr --url=/obm-sync/services/User --ssl --login=prenom.nom --passwd=secret

Note :
        The script will return
                OK if we are able to connect and bind the OBM-Sync server
                WARNING if we are able to connect but not bind to the OBM-Sync server
                CRITICAL if we aren't able to connect to the OBM-Sync server
EOB
}

# get options
Getopt::Long::Configure('bundling');
GetOptions(
  'V|version'         => \$opt_version,
  'h|help'            => \$opt_help,
  't|timeout=i'       => \$TIMEOUT,
  'H|hostname=s'      => \$opt_host,
  'u|url=s'           => \$opt_url,
  's|ssl'             => \$opt_ssl,
  'l|login=s'         => \$opt_login,
  'p|passwd=s'        => \$opt_passwd,

) or do {
  print_usage();
  exit($ERRORS{'UNKNOWN'});
};

if($opt_version) {
  print_version();
  exit($ERRORS{'UNKNOWN'});
}

if($opt_help) {
  print_help();
  exit($ERRORS{'UNKNOWN'});
}

if(!$opt_host) {
  print "Host address option not given\n";
  print_usage();
  exit($ERRORS{'UNKNOWN'});
}

if(!$opt_url) {
  print "URL [OBM-Sync server] option not given\n";
  print_usage();
  exit($ERRORS{'UNKNOWN'});
}

if(!$opt_login) {
  print "Login option not given\n";
  print_usage();
  exit($ERRORS{'UNKNOWN'});
}

if(!$opt_passwd) {
  print "Password option not given\n";
  print_usage();
  exit($ERRORS{'UNKNOWN'});
}

# set alarm in case we hang
$SIG{ALRM} = sub {
  print "CRITICAL - Timeout after $TIMEOUT seconds\n";
  exit($ERRORS{'CRITICAL'});
};
alarm($TIMEOUT);




############################# MAIN ######################
my $protocol = "http://";;
if($opt_ssl) {
  $protocol = "https://";;
}

my $urlstring = $protocol . $opt_host . $opt_url . "/login/doLogin";

#print "My URL = " . $urlstring . "\n";
#print "My Login = " . $opt_login . "\n";
#print "My Pass = " . $opt_passwd . "\n";

my $ua = LWP::UserAgent->new;
$ua->agent("Mozilla 8.0");

#use HTTP::Request::Common qw(POST);

my $req = (POST $urlstring,
 ["login" => "$opt_login",
 "password" => "$opt_passwd",
 "origin" => "lightning[ext:2.2.1.3,light:0.9]"]);

#print "My Request = " . $req . "\n";

my $request = $ua->request($req);
my $content = $request->content;
my $code = $request->code();
# On parse la reponse si code 200

  if ($code <= 299) {

	my $parser = XML::LibXML->new();
	my $source = $parser->parse_string($content);

       if ($source->textContent =~ /^[a-f,0-9]{8}-[a-f,0-9]{4}-[a-f,0-9]{4}-[a-f,0-9]{4}-[a-f,0-9]{12}/) {
                print "OBM-Sync Login OK\n";
                exit($ERRORS{'OK'});
	} else {
	        if ($source->textContent =~ /Login failed for user/) {
			print "Login failed for user";
         		exit($ERRORS{'CRITICAL'});
       		 } else {
                        print $source->textContent;
         	 	exit($ERRORS{'CRITICAL'});
        	}
	}	

  } else {
                        print "Unknown error: ". $request->status_line;
                        exit($ERRORS{'CRITICAL'});
  }


# END



Cordialement,
Laurent Moizo
[email protected]



_______________________________________________
Obm mailing list
[email protected]
http://list.obm.org/mailman/listinfo/obm

Répondre à