[Date Prev]   [Date Next] [Thread Prev]   [Thread Next] [Date Index]   [Thread Index]

 

     [snips-users] https monitor (secmon)

simple, yet effective.  lwp with ssl capabilities is required.

Jerry Wilborn, Operations Engineer
FASTNET - Internet Solutions
610-266-6700
www.fast.net


#!/usr/bin/perl

# jerry wilborn <jerry wilborn at fast.net>
# 9 march 2002

# credit: ed landa <elanda at comstar net>  for snmpgeneric code
# credit: jeremy hough <jeremyh at fast net> ssl code

# use strict;
use vars qw ( $snipsroot $debug $etcdir $bindir $varunits
	      @deviceip @getpage @expect
	    );

BEGIN {
  $snipsroot =  "/home/snips"   unless $snipsroot;	# SET_THIS
  push (@INC, "$snipsroot/etc"); push (@INC, "$snipsroot/bin");
  require "snipsperl.conf" ;		# local customizations
}

use SNIPS;
use LWP::UserAgent;

############################
## Variables customization #  overrides values in the snipslib.pl library
############################
$etcdir  = "$snipsroot/etc"  unless $etcdir;	# location of config file
$bindir  = "$snipsroot/bin"  unless $bindir;

$debug = 0;				# set to 1 for debugging output
$varunits="HTTPS" ;			# the var.units field in EVENT
struct
$s_pollinterval= 60*5;       		# Seconds to sleep between tries.

##########################

##
# Read the config file. Use '\t' as a separator for 'item'
sub readconf  {
  my $lineno = 0;
  my $count = 0;
  my $event = new_event();

  if ($debug == 0 && $libdebug > 0) {
    ++$debug ; --$libdebug;
  }

  $s_sender = 'secmon' if ($s_sender eq "");
  $s_variable = 'HTTPS' if ($s_variable eq "");

  open(CONFIG,"<$s_configfile")||die("Couldn't find $s_configfile,
exiting");
  my $datafd = open_datafile($s_datafile, "w");
  # alter_event($event, $s_sender, undef, undef, undef, undef, $varunits);
  undef @deviceip;

  while(<CONFIG>)
  {
    ++$lineno;
    chomp;
    if(/^\s*\#/) {next;}   	# skip comments
    if(/^\s*$/) {next;}		# skip blank lines

    if (/^(sleepinterval)\s+(\d+)\s*$/i || /^(pollinterval)\s+(\d+)\s*$/i) {
      $s_pollinterval = $2;
      next;
    }
    
    if (/^\s*RRDTOOL\s+ON/i)  { print "RRD ENABLED\n" if $debug;
$SNIPS::dorrd = 1; next; }
    if (/^\s*RRDTOOL\s+OFF/i) { $SNIPS::dorrd = 0; next; }

    if (/^(\S+)\s+(\S+)\s+(\S+)\s+(.+)$/) { # this is a secmon line
      ++$count;
      my $ip = $2;
      ($deviceip[$count], $getpage[$count], $expect[$count]) = ($ip, $3,
$4);
      alter_event($event, $s_sender, $1, $ip, undef, $s_variable,
$varunits);
      write_event($datafd, $event);
      next;
    } else {
      print "Ignoring illegal line: $_\n";
    }
    
  }		# end while(CONFIG)
  
  close(CONFIG);
  if ( $count < 1) { die("Nothing to monitor in $s_configfile, exiting"); }
  if ($debug) {
    print "Devices to monitor are: " ;
    for my $i (1..$count) { print "\t$deviceip[$i]\n"; }
  }
  close_datafile($datafd);

}	# end: sub(readconf)
  
  
# Return   status, value, threshold, maxseverity
sub dotest {
  my ($event, $i) = @_;		# $i starts from 1, not 0
  my $value = "";
  my $cmd = "";
  my $pagedata = "";

  if ($debug > 2) { print "Checking $deviceip[$i] at $getpage[$i]\n"; }

  my $ua = new LWP::UserAgent;
  my $req = new HTTP::Request("GET", "https://$getpage[$i]";);
  my $timeout = $ua->timeout(5);
  my $res = $ua->request($req);
  $pagedata = $res->code . "\n" . $res->content . "\n";

  $value = index(lc($pagedata), $expect[$i]);
  $value = ($value >= 0) ? 0 : 1;

  if ($debug) { print "$expect[$i] and $value\n"; }

  my ($status, $threshold, $severity) = calc_status($value, '1', '1', '1');
  # status, value, thres, maxseverity
  return ($status, $value, $threshold, $severity);

}		# end &dotest()

###
### Main program:
###

&snips_main(\&readconf, undef, \&dotest);

Zyrion Traverse Network Monitoring & Network Management Software