Annotation of nagios/check_jabber_login/check_jabber_login.pl, Revision 1.1
1.1 ! andrew 1: #!/usr/bin/perl -w
! 2: use strict;
! 3: use warnings;
! 4: use lib "/usr/local/libexec/nagios/";
! 5: use utils qw($TIMEOUT %ERRORS &print_revision &support);
! 6: use Getopt::Long;
! 7: use Net::Jabber;
! 8:
! 9: my (
! 10: $opt_version, $opt_help, $opt_port, $opt_host,
! 11: $opt_verbose, $opt_uname, $opt_pass, $opt_ssl,
! 12: );
! 13:
! 14: my $state = 'UNKNOWN';
! 15: my $PROGNAME = "check_jabber_login";
! 16: sub print_help ();
! 17: sub print_usage ();
! 18:
! 19: %ENV = ();
! 20:
! 21: Getopt::Long::Configure('bundling');
! 22: GetOptions(
! 23: "V|version" => \$opt_version,
! 24: "h|help" => \$opt_help,
! 25: "v|verbose+" => \$opt_verbose,
! 26: "H|hostname=s" => \$opt_host,
! 27: "P|port=i" => \$opt_port,
! 28: "s|ssl" => \$opt_ssl,
! 29: "u|username=s" => \$opt_uname,
! 30: "p|password=s" => \$opt_pass
! 31: );
! 32:
! 33: $opt_port ||= 5222;
! 34:
! 35: # -h means display verbose help screen
! 36: if ($opt_help) { print_usage(); exit $ERRORS{'OK'}; }
! 37:
! 38: # -V means display version number
! 39: if ($opt_version) {
! 40: print_revision( $PROGNAME, '$Revision: 1.1 $ ' );
! 41: exit $ERRORS{'OK'};
! 42: }
! 43:
! 44: if ( !$opt_host || !$opt_port || !$opt_uname || !$opt_pass ) {
! 45: print_usage();
! 46: exit $ERRORS{'UNKNOWN'};
! 47: }
! 48:
! 49: if ( !utils::is_hostname($opt_host) ) {
! 50: print "$opt_host is not a valid host name\n";
! 51: print_usage();
! 52: exit $ERRORS{"UNKNOWN"};
! 53: }
! 54: $SIG{'ALRM'} = sub {
! 55: print("ERROR: No response from server (alarm)\n");
! 56: exit $ERRORS{"UNKNOWN"};
! 57: };
! 58: alarm($TIMEOUT);
! 59:
! 60: checklogin();
! 61:
! 62: sub checklogin {
! 63: my $jabbercm = $opt_host;
! 64: my $jabbercmport = $opt_port;
! 65: my $username = $opt_uname;
! 66: my $password = $opt_pass;
! 67: my $is_ssl = 0;
! 68: my $debug = 0;
! 69: $is_ssl = '1' if defined $opt_ssl;
! 70: $debug = '2' if defined $opt_verbose;
! 71:
! 72: my $ocon = new Net::Jabber::Client(
! 73: debuglevel => $debug,
! 74: file => 'stdout'
! 75: );
! 76: if ( !$ocon->Connect(
! 77: 'hostname' => $jabbercm,
! 78: 'port' => $jabbercmport
! 79: )
! 80: ) {
! 81: print "CRITICAL: Connection error $jabbercm:$jabbercmport\n";
! 82: exit $ERRORS{'CRITICAL'};
! 83: }
! 84:
! 85: my @resp = $ocon->AuthSend(
! 86: username => $username,
! 87: password => $password,
! 88: resource => 'Nagios',
! 89: tls => $is_ssl
! 90: );
! 91: if ( $resp[0] ne "ok" ) {
! 92: print "WARNING: Login error for $username\n";
! 93: exit $ERRORS{'WARNING'};
! 94: }
! 95: $ocon->Disconnect();
! 96:
! 97: print "OK: Login for $username successful\n";
! 98: exit $ERRORS{'OK'};
! 99: }
! 100:
! 101: sub print_usage () {
! 102: print "Usage: \n";
! 103: print " $PROGNAME -H host -P port -u username -p password [-s] [--ssl]\n";
! 104: print " $PROGNAME [-h | --help]\n";
! 105: print " $PROGNAME [-V | --version]\n";
! 106: }
! 107:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>