I'd be glad to :)  But first I have to admit that I'm not a coder by 
profession.  I just write what I write to help me be a better network engineer 
:)

Couple things to note:

1. It's probably not the most portable code.  You will have to check/correct 
the snmp log file, ping log file, and the output file
2. You will have to have system level tail, cut, and grep available
3. I recommend installing the script in $ZENHOME/libexec
4. And then you will have to setup the datapoints/graphs in zenoss

I will be more than happy to help in any way I can.  If anyone notices any 
obvious improvements, I'd be glad to hear them.  I'm always looking for ways to 
make life better!!

Hope this helps someone else!!

-Russ


Code:

#! /usr/bin/perl
# Author: Russ Uhte
# Date: 6/14/2008
# get_zen_stats.pl

# Right now, this scirpt will only pull snmp and ping stats
# Make sure you enter your logfiles

use Time::Local;
use strict;

my $snmp_file = '/opt/zenoss/log/zenperfsnmp.log';
my $ping_file = '/opt/zenoss/log/zenping.log';

my $out_file = '/opt/zenoss/log/get_zen_stats.log';

# if the file containing the last collection time doesn't exist, create it
if(!-e $out_file){
    my $time = time();
    open(OUT, ">$out_file") or die("Couldn't open $out_file: $!\n");
    print(OUT "S $time\n");
    print(OUT "P $time\n");
    close(OUT)
}
my $last_s_time = `tail -n 2 $out_file | grep S | cut -d " " -f 2`;
my $last_p_time = `tail -n 2 $out_file | grep P | cut -d " " -f 2`;

my @s_lines = `grep " zen\.zenperfsnmp: collected " $snmp_file`;
my @p_lines = `grep " zen\.ZenPing: Finished pinging " $ping_file`;

my $coltime = "$last_s_time";
my $s_dev_total = "0";
my $s_dev_col = "0";
my $s_col_secs = "0";

foreach my $line (@s_lines){
    next unless ($line =~ /(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2}) 
INFO zen\.zenperfsnmp: collected (\d+) of (\d+) devices in (\d+\.\d+)/);
    my $colyear = $1;
    my $colmon = $2;
    $colmon -= 1;
    my $colday = $3;
    my $colhour = $4;
    my $colmin = $5;
    my $colsec = $6;

    $coltime = timelocal($colsec, $colmin, $colhour, $colday, $colmon, 
$colyear);

    next if ($coltime < $last_s_time);
    $s_dev_col = $7;
    $s_dev_total = $8;
    $s_col_secs = $9;
}
open(OUT, ">>$out_file") or die("Couldn't open $out_file: $!\n");
print(OUT "S $coltime\n");


$coltime = "$last_p_time";

chomp($coltime);
my $p_dev_col = "0";
my $p_col_secs = "0";

foreach my $line (@p_lines){
    next unless ($line =~ /(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2}) 
INFO zen\.ZenPing: Finished pinging (\d+) jobs in (\d+\.\d+) seconds/);
    my $colyear = $1;
    my $colmon = $2;
    $colmon -= 1;
    my $colday = $3;
    my $colhour = $4;
    my $colmin = $5;
    my $colsec = $6;

    $coltime = timelocal($colsec, $colmin, $colhour, $colday, $colmon, 
$colyear);

    next if ($coltime < $last_p_time);
    $p_dev_col = $7;
    $p_col_secs = $8;
}

print(OUT "P $coltime\n");
close(OUT);

print("GetZenStats OK|SNMPTotDevs=$s_dev_total SNMPResDevs=$s_dev_col 
SNMPTime=$s_col_secs PINGTotDevs=$p_dev_col PINGTime=$p_col_secs");







-------------------- m2f --------------------

Read this topic online here:
http://community.zenoss.com/forums/viewtopic.php?p=21678#21678

-------------------- m2f --------------------



_______________________________________________
zenoss-users mailing list
[email protected]
http://lists.zenoss.org/mailman/listinfo/zenoss-users

Reply via email to