[Mon-commit] mon mon,1.4.2.10,1.4.2.11
                
                Brought to you by:
                
                    trockij
                    
                
            
            
        
        
        
    | 
     
      
      
      From: Jim T. <tr...@us...> - 2004-08-03 15:44:52
      
     
   | 
Update of /cvsroot/mon/mon In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11885 Modified Files: Tag: mon-1-0-0pre1 mon Log Message: removed snmp stuff which doesn't work and won't work any time soon call_alert should not call waitpid, it only needs to call close, since perl's close will call waitpid for us. calling waitpid after closing a filehandle opened with open(FH, "|-") will always return an error, which is what it was doing. added MON_CFBASEDIR var to monitor and alert environments Index: mon =================================================================== RCS file: /cvsroot/mon/mon/mon,v retrieving revision 1.4.2.10 retrieving revision 1.4.2.11 diff -C2 -d -r1.4.2.10 -r1.4.2.11 *** mon 2 Aug 2004 19:47:31 -0000 1.4.2.10 --- mon 3 Aug 2004 15:44:42 -0000 1.4.2.11 *************** *** 54,59 **** use Time::HiRes qw(gettimeofday tv_interval usleep); use Time::Period; - use Mon::SNMP; - #use SNMP in read_cf() sub auth; --- 54,57 ---- *************** *** 83,87 **** sub gen_scriptdir_hash; sub handle_io; - sub handle_snmp_trap; sub handle_trap; sub handle_trap_timeout; --- 81,84 ---- *************** *** 165,169 **** my %NOAUTHCMDS; my %AUTHTRAPS; - my %AUTHSNMPTRAPS; # --- 162,165 ---- *************** *** 971,986 **** } - } elsif ($1 eq "snmp") { - if ($2 =~ /^1|yes|on|true$/i) { - $new_CF{"SNMP"} = 1; - eval "use SNMP"; - if ($@ ne "") { - close (CFG); - return "cf error: could not use SNMP: $@"; - } - } else { - $new_CF{"SNMP"} = 0; - } - } elsif ($1 eq "monerrfile") { $new_CF{"MONERRFILE"} = $2; --- 967,970 ---- *************** *** 995,1001 **** } - } elsif ($1 eq "snmpport") { - $new_CF{"SNMPPORT"} = $2; - } elsif ($1 eq "dep_recur_limit") { $new_CF{"DEP_RECUR_LIMIT"} = $2; --- 979,982 ---- *************** *** 1769,1784 **** configure_filehandle (*TRAPSERVER) || die_die ("err", "could not configure UDP trap port: $!"); - - return if (!$CF{"SNMP"}); - - # - # SNMP traps - # - socket (SNMPSERVER, PF_INET, SOCK_DGRAM, $udpproto) || - die_die ("err", "could not create UDP socket: $!"); - bind (SNMPSERVER, sockaddr_in ($CF{"SNMPPORT"}, INADDR_ANY)) || - die_die ("err", "could not bind UDP server port: $!"); - configure_filehandle (*SNMPSERVER) || - die_die ("err", "could not configure UDP SNMP port: $!"); } --- 1750,1753 ---- *************** *** 3216,3219 **** --- 3185,3189 ---- $ENV{"MON_STATEDIR"} = $CF{"STATEDIR"}; $ENV{"MON_LOGDIR"} = $CF{"LOGDIR"}; + $ENV{"MON_CFBASEDIR"} = $CF{"CFBASEDIR"}; if (!exec @args) *************** *** 3580,3584 **** %NOAUTHCMDS = (); %AUTHTRAPS = (); - %AUTHSNMPTRAPS = (); $sect = "command"; --- 3550,3553 ---- *************** *** 3600,3606 **** $sect = "trap"; next; - } elsif ($l =~ /^snmp trap section/) { - $sect = "snmptrap"; - next; } --- 3569,3572 ---- *************** *** 3655,3668 **** $AUTHTRAPS{$host}{$user} = $password; - } elsif ($sect eq "snmptrap") { - - if ($l !~ /^(\S+)\s+(\S+)$/) { - syslog ('err', "invalid line in $CF{AUTHFILE}, line $."); - next; - } - - ($host, $password) = ($1, $2); - $AUTHSNMPTRAPS{$host}{$password} = 1; - } else { syslog ('err', "unknown section in $CF{AUTHFILE}: $l"); --- 3621,3624 ---- *************** *** 3754,3793 **** # - # handle SNMP trap - # - sub handle_snmp_trap { - my ($buf, $from) = @_; - my ($port, $addr, $fromip); - my (%traphash); - - ($port, $addr) = sockaddr_in ($from); - $fromip = inet_ntoa ($addr); - - if (!defined ($AUTHSNMPTRAPS{$fromip})) { - syslog ('err', "got SNMP trap from unauthorized agent: $fromip"); - return undef; - } - - $TRAP_PDU->buffer ($buf); - %traphash = $TRAP_PDU->decode; - - if (! keys %traphash) { - syslog ('err', "error decoding SNMP trap: " . $TRAP_PDU->error); - return undef; - } - - if ($AUTHSNMPTRAPS{$fromip} ne - crypt ($traphash{"community"}, $traphash{"community"})) { - syslog ('err', "unauthorized community from agent: $fromip"); - return undef; - } - - # - # here's the real meat - # - } - - - # # handle a trap # --- 3710,3713 ---- *************** *** 4027,4031 **** vec ($iovec, fileno (TRAPSERVER), 1) = 1; vec ($iovec, fileno (SERVER), 1) = 1; - vec ($iovec, fileno (SNMPSERVER), 1) = 1 if ($CF{"SNMP"}); foreach my $cl (keys %clients) { vec ($iovec, $cl, 1) = 1; --- 3947,3950 ---- *************** *** 4056,4071 **** # - # SNMP trap - # - } elsif ($CF{"SNMP"} && vec ($niovec, fileno (SNMPSERVER), 1)) { - my ($from, $trapbuf); - if (!defined ($from = recv (SNMPSERVER, $trapbuf, 65536, 0))) { - syslog ('err', "error trying to recv an SNMP trap: $!"); - } else { - handle_snmp_trap ($trapbuf, $from); - } - next; - - # # client connections # --- 3975,3978 ---- *************** *** 4336,4341 **** $CF{"CLIENTALLOW"} = '\d+.\d+.\d+.\d+'; $CF{"MAXPROCS"} = 0; - $CF{"SNMP"} = 0; - $CF{"SNMPPORT"} = 34000; $CF{"HISTORICFILE"} = ""; $CF{"HISTORICTIME"} = 0; --- 4243,4246 ---- *************** *** 4412,4417 **** %MONITORHASH = (); %ALERTHASH = (); - - $TRAP_PDU = new Mon::SNMP; } --- 4317,4320 ---- *************** *** 4593,4596 **** --- 4496,4500 ---- $ENV{"MON_STATEDIR"} = $CF{"STATEDIR"}; $ENV{"MON_LOGDIR"} = $CF{"LOGDIR"}; + $ENV{"MON_CFBASEDIR"} = $CF{"CFBASEDIR"}; if( defined($sref->{"_intended"}) ) *************** *** 4633,4642 **** print ALERT $args{"output"}; close (ALERT); - waitpid $pid, 0; - - # - # test alerts don't count - # - return (1) if ($args{"flags"} & $FL_TEST); my $exitval = $? >> 8; --- 4537,4540 ---- *************** *** 4645,4649 **** { syslog ("err", "child alert for " . ! " $args{group}/$args{service} " . "failed, exited with $exitval"); return undef; --- 4543,4547 ---- { syslog ("err", "child alert for " . ! "$args{group}/$args{service} " . "failed, exited with $exitval"); return undef; *************** *** 4651,4654 **** --- 4549,4557 ---- # + # test alerts don't count + # + return (1) if ($args{"flags"} & $FL_TEST); + + # # tally this alert #  |