1 Reply Latest reply on Nov 17, 2013 2:47 PM by stripet

    monitoring a service in Linux server

    Guilherme Silva Gomes

      I wonder if we can add to the Orion monitoring, monitoring a service.

      Linux server

      1 - Where you need to log in via SSH even
      2 - Run a command
      3 - Analyze the output

      Once connected to the server give the command listq

      rabbitmq @ pc-00114: ~ $ listq
      name ready unack uncommitted messages memory
      Listing queues ...
      RECEIPT 0 0 3936 0 0
      HED 3936 0 0 0 0
      AMZ 3936 0 0 0 0
      HMB 3936 0 0 0 0
      HEM 1 0 0 1 5800
      SEDI 5800 0 0 0 0
      HGPJ 3936 0 0 0 0
      ... done.


      Where have columns with the number 0.

      If the result is the same 10 forwards an alarm.
      Greater than 5 alert
      Less than 5 ok.

        • Re: monitoring a service in Linux server
          stripet

          Try this Perl Script in a Linux/UNIX Script SAM Template Component:

           

          Script Arguments:  perl ${SCRIPT}

           

          Script Body:

           

          #/usr/bin/perl

          # listq monitor for Linux systems

           

          $message = "" ;

          my $mydate = `date +'%m/%d/%Y %H:%M:%S'` ;

          my $warnthresh = 1 ;

          my $critthresh = 5 ;

          my $warncounter = 0 ;

          my $critcounter = 0 ;

           

          $listqout = `listq >/tmp/SW_listqout 2>&1` ;

          $LISTQFILE = "/tmp/SW_listqout" ;

          open(LISTQFILE) or die("Message: listq command FAILED") ;

          while (my $line = <LISTQFILE>) {

          #       $line = chomp($line) ;

                  ($lqname,$lqready,$lqunack,$lquncommitted,$lqmessages,$lqmemory) = split(/\s+/,$line) ;

          #        print "name is " . $lqname . "\n" ;

          #        print "ready for " . $lqname . " is: " . $lqready . "\n" ;

          #        print "unack for " . $lqname . " is: " . $lqunack . "\n" ;

          #        print "uncommitted for " . $lqname . " is: " . $lquncommitted . "\n" ;

          #        print "messages for " . $lqname . " is: " . $lqmessages . "\n" ;

          #        print "memory for " . $lqname . " is: " . $lqmemory . "\n" ;

           

                  if ( ($lqname eq "sh\:") && ($lqready eq "listq\:") && ($lqunack eq "command") && ($lquncommitted eq "not") && ($lqmessages eq "found") ) {

                          print "Message:  listq command not found.  See the " . $LISTQFILE . " file for error details.  " . $message . " " . $mydate . "\n";

                          print "Statistic: 3\n";

                          exit 3;

                  }

           

                  if ( ($lqname eq "sh\:") ) {

                          print "Message:  listq command failed for some reason.  See the " . $LISTQFILE . " file for error details.  " . $message . " " . $mydate . "\n";

                          print "Statistic: 3\n";

                          exit 3;

                  }

                  next if ($lqname eq "name") ;

                  next if ($lqname eq "Listing") ;

           

                  if ($lqready >= $warnthresh) {

                          if ($lqready >= $critthresh) {

                                  $critcounter = $critcounter+1 ;

          #                        print "Critical triggered for " . $lqname . " with " . $lqready . " ready" . "\n" ;

                                  $message = $message . "   " . $lqname . " has " . $lqready . " ready \(Critical\)" ;

                          } else {

                                  $warncounter = $warncounter+1 ;

          #                        print "Warning triggered for " . $lqname . " with " . $lqready . " ready" . "\n" ;

                                  $message = $message . "   " . $lqname . " is " . $lqready . " ready \(Warning\)" ;

                          }

                  }

           

           

                  if ($lqunack >= $warnthresh) {

                          if ($lqunack >= $critthresh) {

                                  $critcounter = $critcounter+1 ;

          #                        print "Critical triggered for " . $lqname . " with " . $lqunack . " unack" . "\n" ;

                                  $message = $message . "   " . $lqname . " has " . $lqunack . " unack \(Critical\)" ;

                          } else {

                                  $warncounter = $warncounter+1 ;

          #                        print "Warning triggered for " . $lqname . " with " . $lqunack . " unack" . "\n" ;

                                  $message = $message . "   " . $lqname . " is " . $lqunack . " unack \(Warning\)" ;

                          }

                  }

           

                  if ($lquncommitted >= $warnthresh) {

                          if ($lquncommitted >= $critthresh) {

                                  $critcounter = $critcounter+1 ;

          #                        print "Critical triggered for " . $lqname . " with " . $lquncommitted . " uncommitted" . "\n" ;

                                  $message = $message . "   " . $lqname . " has " . $lquncommitted . " uncommitted \(Critical\)" ;

                          } else {

                                  $warncounter = $warncounter+1 ;

          #                        print "Warning triggered for " . $lqname . " with " . $lquncommitted . " uncommitted" . "\n" ;

                                  $message = $message . "   " . $lqname . " is " . $lquncommitted . " uncommitted \(Warning\)" ;

                          }

                  }

           

           

                  if ($lqmessages >= $warnthresh) {

                          if ($lqmessages >= $critthresh) {

                                  $critcounter = $critcounter+1 ;

          #                        print "Critical triggered for " . $lqname . " with " . $lqmessages . " messages" . "\n" ;

                                  $message = $message . "   " . $lqname . " has " . $lqmessages . " messages \(Critical\)" ;

                          } else {

                                  $warncounter = $warncounter+1 ;

          #                        print "Warning triggered for " . $lqname . " with " . $lqmessages . " messages" . "\n" ;

                                  $message = $message . "   " . $lqname . " is " . $lqmessages . " messages \(Warning\)" ;

                          }

                  }

           

                  if ($lqmemory >= $warnthresh) {

                          if ($lqmemory >= $critthresh) {

                                  $critcounter = $critcounter+1 ;

          #                        print "Critical triggered for " . $lqname . " with " . $lqmemory . " memory" . "\n" ;

                                  $message = $message . "   " . $lqname . " has " . $lqmemory . " memory \(Critical\)" ;

                          } else {

                                  $warncounter = $warncounter+1 ;

          #                        print "Warning triggered for " . $lqname . " with " . $lqmemory . " memory" . "\n" ;

                                  $message = $message . "   " . $lqname . " is " . $lqmemory . " memory \(Warning\)" ;

                          }

                  }

           

          }

          if ($warncounter > 0) {

                  if ($critcounter > 0 ) {

                          print "Message:  One or more listq queues exceeded the Critical \(\>\=$critthresh\%\) and\/or Warning \(\>\=$warnthresh\%\) Threshold\!   " . $message . " " . $mydate . "\n";

                          print "Statistic: 3\n";

                          exit 3;

                  } else {

                          print "Message: One or more listq queues exceeded the Warning \(\>\=$warnthresh\%\) Threshold\!   " . $message . " " . $mydate . "\n";

                          print "Statistic: 2" . "\n";

                          exit 2;

                  }

          } else {

                  if ($critcounter > 0 ) {

                          print "Message: One or more listq queues exceeded the Critical Threshold\(\>\=$critthresh\%\)\!  " . $message . " " . $mydate . "\n";

                          print "Statistic: 3" . "\n";

                          exit 3;

                  } else {

                          $message = "All listq queues are Normal " . $mydate . "\n" ;

                          print "Message: " . $message . "\n" ;

                          print "Statistic: 0" . "\n";

                          exit 0;

                  }

          }