Author: glen                         Date: Mon Mar  1 16:06:29 2010 GMT
Module: packages                      Tag: HEAD
---- Log message:
- check users status
- fix variable conflict with $status
- fix return from parse loop

---- Files affected:
packages/nagios-plugin-check_asterisk_skype:
   check_asterisk_skype (1.4 -> 1.5) 

---- Diffs:

================================================================
Index: packages/nagios-plugin-check_asterisk_skype/check_asterisk_skype
diff -u packages/nagios-plugin-check_asterisk_skype/check_asterisk_skype:1.4 
packages/nagios-plugin-check_asterisk_skype/check_asterisk_skype:1.5
--- packages/nagios-plugin-check_asterisk_skype/check_asterisk_skype:1.4        
Mon Mar  1 16:26:58 2010
+++ packages/nagios-plugin-check_asterisk_skype/check_asterisk_skype    Mon Mar 
 1 17:06:24 2010
@@ -50,15 +50,15 @@
        while (<$fh>) {
                chomp;
 
-               if (my($file, $key, $expires, $hostid, $channels, $status) = m/
+               if (my($file, $key, $expires, $hostid, $channels, $state) = m/
                        File:\s+(\S+)\s+--\s+
                        Key:\s+(\S+)\s+--\s+
                        Expires:\s+([-\d]+)\s+--\s+
                        Host-ID:\s+([\da-f:]+)\s+--\s+
                        Channels:\s+(\d+)\s+\((\S+)\)
                        /x) {
-                       $message .= "License $status: $channels channels, 
expires $expires";
-                       if ($status ne 'OK') {
+                       $message .= "License $state: $channels channels, 
expires $expires";
+                       if ($state ne 'OK') {
                                $status = $ERRORS{CRITICAL};
                        }
                        next;
@@ -68,12 +68,64 @@
                if (/ERROR:|Unable to connect/) {
                        $status = $ERRORS{CRITICAL};
                        $message .= $_;
-                       return;
+                       next;
                }
        }
        close $fh || die "asterisk exited with: $?\n";
 }
 
+sub check_skype_user {
+
+       my $pid = open(my $fh, '-|');
+       if ($pid == 0) {
+               # child
+               # redirect stderr
+               open STDERR, '>&STDOUT';
+               my @CMD = ('asterisk', '-rx', 'skype show users');
+               exec @CMD or die "ERROR: Could not execute '@CMD': $!\n";
+
+       } elsif($pid == -1) {
+               die("fork() failed");
+       }
+
+       # parent
+       my $in = 0;
+       my @status;
+       while (<$fh>) {
+               chomp;
+
+               $in = 1,next if /Skype Users/;
+               next unless $in;
+
+               if (my ($user, $state) = /^(\S+):\s+(.*)/) {
+                       push(@status, $state);
+                       # Connecting to P2P Network => WARNING
+                       # Connecting to Server => WARNING
+                       # Logged In => OK
+                       if ($state ne 'Logged In') {
+                               # assume warning
+                               $status = $ERRORS{WARNING} unless $status;
+                       }
+                       next;
+               }
+
+               # This proceses STDERR messages
+               if (/ERROR:|Unable to connect/) {
+                       $status = $ERRORS{CRITICAL};
+                       $message .= $_;
+                       next;
+               }
+       }
+       close $fh || die "asterisk exited with: $?\n";
+
+       if (@status) {
+               $message .= "; User: ".join(', ', @status);
+       } else {
+               $status = $ERRORS{WARNING} unless $status;
+               $message .= "; No skype user setup";
+       }
+}
+
 #####################################################################
 $ENV{'BASH_ENV'} = '';
 $ENV{'ENV'} = '';
@@ -98,6 +150,7 @@
 $message = '';
 
 check_skype_license;
+check_skype_user;
 
 if ($message) {
        if ($status == $ERRORS{OK}) {
================================================================

---- CVS-web:
    
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/nagios-plugin-check_asterisk_skype/check_asterisk_skype?r1=1.4&r2=1.5&f=u

_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to