3 Replies Latest reply on Aug 22, 2019 5:00 PM by tomiannelli

    Basic running a script and reading the output or reading a log file LINUX

    tmcurry

      Need help changing a custom mon script from a different tool to solarwinds.

       

      NAMonitor.sh:

      result:$alarm:NA commands issued in the past 5 minutes $count

       

       

      $alarm is used to decide which the severity

      be one of the following integers:

      0 (clear), 1 (warning), or 2 (critical)

       

       

      Sample output:

      result:2:NNA commands issued in the past 5 minutes 25

      (located at /app/scripts/log/NAMonitor.log

       

       

      This file will be

      updated every 5 minutes)

       

      Choices:

      1. i can execute the NAMonitor.sh

      2. I can read a log  /app/scripts/log/NAMonitor.log

      I cannot have the contents of the  NAMonitor.sh

       

      The entry is one line and : delimited

       

       

      The Goal:

      read the $alarm variable which will give a number 0|1|2 I assume this would relate to $stat

      The rest of the line NNA commands issued in the past 5 minutes 25 would be the $message.

       

       

      Note I read: Log Parser (Perl)  I also looked at carious examples. I am missing something probably really obvious.  I have a lot of these so I know if I get the first one the rest will fall  in line.

        • Re: Basic running a script and reading the output or reading a log file LINUX
          tomiannelli

          A component monitor is keying off of the out formatted as:

           

          MESSAGE: <SOME TEXT>

          STATISTIC: <SOME VALUE>

           

          If you want more outputs you can use:

          MESSAGE.<LABEL1>:<SOME TEXT>

          STATISTIC.<LABEL1>:<SOME VALUE>

          MESSAGE.<LABEL2>:<SOME TEXT>

          STATISTIC.<LABEL2>:<SOME VALUE>

          MESSAGE.<LABEL3>:<SOME TEXT>

          STATISTIC.<LABEL3>:<SOME VALUE>

           

          In a perl script output you might see something like:

          # some perl code that executes your NAMonitor.sh and captures $message and $alarm

          # It looks easy enough to split the result output result:2:NNA commands issued in the past 5 minutes 25

          # Open the file /app/scripts/log/NAMonitor.log

          my $filename = '/app/scripts/log/NAMonitor.log;

          open(my $fh, '<:encoding(UTF-8)', $filename);

          my $str = readline $fh;

          my @words = split /:/, $str;

          $message = $words[2];

          $alarm = $words[1];

          printf("Message: The NNA Commands issued: %d . \n", $message);

          printf("Statistic: %d\n", $alarm);

           

          This output would be collected by a SAM template Component and you can then set up an alert based on the alarm statistic.

          1 of 1 people found this helpful