Xymon Mailing List Archive search

How to grab time-since-last-change for a test?

5 messages in this thread

list David Mills · Wed, 14 Nov 2012 20:16:19 +0000 ·
All -

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

Thanks!

david


~~~~~~~~~~~~~~~~~~~
David Mills
Systems Administrator
Northrop Grumman
XXX-XXX-XXXX
user-eb64c112f0e9@xymon.invalid
list Jeremy Laidman · Thu, 15 Nov 2012 10:42:10 +1100 ·
quoted from David Mills
On 15 November 2012 07:16, Mills, David (IS) <user-eb64c112f0e9@xymon.invalid> 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
list David Mills · Thu, 15 Nov 2012 17:36:46 +0000 ·
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]);
quoted from Jeremy Laidman
}

From: Jeremy Laidman [mailto:user-71895fb2e44c@xymon.invalid]
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) <user-eb64c112f0e9@xymon.invalid<mailto:user-eb64c112f0e9@xymon.invalid>> 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
list Nicolas Lienard · Thu, 15 Nov 2012 19:27:10 +0100 ·
Hi David;


Drop these lines:
quoted from David Mills
my $HOB_BIN = "/usr/local/xymon/client/bin";
my $HOB_SERV = "XXX.XXX.XXX.XXX";                  # Substitute the FQDN or IP for your Hobbit server
Then change this line to have a filter with the high days on top and using xymon variable ( i use BB to have compatibility with older version, adapt as well).

my @current_non_green_hosts = `$ENV{BB} $ENV{BBDISP} "xymondboard color=red,yellow,purple fields=hostname,testname,color,lastchange" | sort --field-separator="|" -k4`;

cheers
nico
quoted from David Mills


Le 15 nov. 2012 à 18:36, Mills, David (IS) a écrit :
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:user-71895fb2e44c@xymon.invalid] 
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) <user-eb64c112f0e9@xymon.invalid> 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
 
list David Mills · Thu, 15 Nov 2012 18:55:08 +0000 ·
Thanks for the good idea, Nico...

;)
quoted from Nicolas Lienard

From: Nico [mailto:user-4f1d872b9031@xymon.invalid]
Sent: Thursday, November 15, 2012 12:27 PM
To: Mills, David (IS)
Cc: Jeremy Laidman; xymon at xymon.com
Subject: Re: [Xymon] EXT :Re: How to grab time-since-last-change for a test?

Hi David;


Drop these lines:

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

Then change this line to have a filter with the high days on top and using xymon variable ( i use BB to have compatibility with older version, adapt as well).

my @current_non_green_hosts = `$ENV{BB} $ENV{BBDISP} "xymondboard color=red,yellow,purple fields=hostname,testname,color,lastchange" | sort --field-separator="|" -k4`;

cheers
nico


Le 15 nov. 2012 à 18:36, Mills, David (IS) a écrit :


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:user-71895fb2e44c@xymon.invalid]
Sent: Wednesday, November 14, 2012 5:42 PM
To: Mills, David (IS)
Cc: xymon at xymon.com<mailto: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) <user-eb64c112f0e9@xymon.invalid<mailto:user-eb64c112f0e9@xymon.invalid>> 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