[Xymon] EXT :Re: How to grab time-since-last-change for a test?

Mills, David (IS) David.Mills at ngc.com
Thu Nov 15 18:36:46 CET 2012


Jeremy -

Many thanks / that's exactly what I needed. Now time to "give back". I'm pasting the little Perl script I wrote to summarize, in tabular format, all non-green alerts currently older than a week...

=== Sample output (appears 'tabular' in fixed font):

** Host Name **                                   ** Test **     ** Color **    ** Days Since Change **
ApntmntDtlSrvc_A                                     http           red               9.91
App-Completed                                        http           red               9.91
App-Complete_B                                       http           red               9.91
App-Complete_C                                       http           red               9.91
App-Complete_D                                       http           red               9.91
...

=== Code:  ('Hope this helps someone!)
#!/usr/bin/perl

#------------------------------------------------------------------------------------------------
#   Extract list of "stale" alerts from Xymon server / format list as 4-column table:
#       Host / (non-green) Test / (current) Color / # of days since last change
#
#   11/15/12 -- david mills
#------------------------------------------------------------------------------------------------

use strict;

my $HOB_BIN = "/usr/local/xymon/client/bin";
my $HOB_SERV = "XXX.XXX.XXX.XXX";                  # Substitute the FQDN or IP for your Hobbit server

my $grace_period_in_secs = 7 * 24 * 60 * 60;    #  1 week expressed as seconds
my $grace_period_threshold = (time - $grace_period_in_secs);

my @current_non_green_hosts = `$HOB_BIN/xymon $HOB_SERV "xymondboard color=red,yellow,purple fields=hostname,testname,color,lastchange"`;

my $col1_margin = 50;                   # Output col width
my $other_cols_margin = 15;
printf("%-${col1_margin}s%-${other_cols_margin}s%-${other_cols_margin}s%-${other_cols_margin}s%-${other_cols_margin}s\n",
        "** Host Name **",
        "** Test **",
        "** Color **",
        "** Days Since Change **" );

foreach my $host_rec ( @current_non_green_hosts ) {
   my @flds = split /\|/, $host_rec;

   my $days_since_last_change = (time - $flds[3]) / (60 * 60 * 24);
   printf("%-${col1_margin}s   %-${other_cols_margin}s%-${other_cols_margin}s   %.2f\n",
        @flds[0..2],
        $days_since_last_change)
      if ($grace_period_threshold >= $flds[3]);
}

From: Jeremy Laidman [mailto:jlaidman at rebel-it.com.au]
Sent: Wednesday, November 14, 2012 5:42 PM
To: Mills, David (IS)
Cc: xymon at xymon.com
Subject: EXT :Re: [Xymon] How to grab time-since-last-change for a test?

On 15 November 2012 07:16, Mills, David (IS) <David.Mills at ngc.com<mailto:David.Mills at ngc.com>> wrote:
All -

What is the easiest way to grab the timestamp of the last status change for given host / test from a script?

Maybe something like this:

xymoncmd xymon localhost 'xymondboard host=hostname test=cpu fields=hostname,testname,color,lastchange'

For more info, see the "xymondboard" section of the "xymon" man page: http://xymon.org/xymon/help/manpages/man1/xymon.1.html.

J

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xymon.com/pipermail/xymon/attachments/20121115/f97cc439/attachment.html>


More information about the Xymon mailing list