Debian Codegraph @

contrib/ovmrtg/ovdel

raw
1 #!/usr/local/bin/perl5
2 # -*- mode: Perl -*-
3 ##################################################################
4 # This file controls the deletion of the MRTG monitoring from OV
5 ##################################################################
6 # Created by Laurie Gellatly <[email protected]>
7 #################################################################
8 #
9 # Distributed under the GNU copyleft
10 #
11 # $Id: ovdel,v 1.1.1.1 2002/02/26 10:16:36 oetiker Exp $
12 #
13 use Socket;
14 use strict;
15 use vars '$DEBUG';
16 my $DEBUG = 0;
17 my $company = "Company";
18 my $rundir = "/opt/mrtg/run";
19 my $webdir = "/var/opt/ns-fasttrack/docs/mrtg/";
20 my $cronfile = "mrtgc";
21 my $roothtml = "routers.html";
22 my $ov_conf = "/etc/opt/OV/share/conf";
23 my $ovconf = $ov_conf."/snmpCol.conf";
24 my $buildhtf = "buildht";
25 my $dnsfile = "ovmrtgc.csv";
26
27 # Change the next line to " &" if all jobs are to be submitted at once
28 my $backgrnd = " ";
29
30 my($router,$sysn,$sysncfg,$sysnhtml,$head,$cnt,$at);
31 my(@sysipnms,@mrtgc,@mrtgd,@sysnms,@ovconfd,@ovmrtgc,@buildhtt);
32
33 sub main {
34
35 $router = $ARGV[0];
36 die <<USAGE unless $router;
37
38 USAGE: ovdel 'router IP ADDRESS/S'
39
40 EXAMPLE: ovdel 193.21.1.2 10.21.1.2 10.21.1.1
41
42
43 USAGE
44 chdir $rundir;
45 @sysipnms=`perl ovsysnms @ARGV`;
46 chomp(@sysipnms);
47 # Figure out what needs not be monitored and change the conf file
48 `perl $rundir\/ovcols - @ARGV > collects`;
49 `xnmcollect -merge collects`;
50 # eventaully HP may decide to remove lines using xnmcollect and then we would
51 # not need the following loop:
52 open (SNMPCOL,"<".$ovconf);
53 # This next piece of code removes any lines in snmpCol.conf that start with XC
54 while(<SNMPCOL>){
55 if (/^XC /){
56 next;
57 } else {
58 $ovconfd[@ovconfd] = $_;
59 }
60 }
61 close (SNMPCOL);
62 open (SNMPCOL,">".$ovconf);
63 for ($cnt = 0; $cnt < @ovconfd ; $cnt++){
64 print SNMPCOL "$ovconfd[$cnt]";
65 }
66 close (SNMPCOL);
67 `xnmcollect -event`;
68
69 # Remove the .cfg and .ok files as no longer needed
70 for ($cnt = 0; $cnt < @sysipnms ; $cnt++){
71 ($router,$mrtgd[@mrtgd]) = split /\,/, lc($sysipnms[$cnt]);
72 unlink($mrtgd[$cnt].".cfg",$mrtgd[$cnt].".ok");
73 }
74 @mrtgd = sort(@mrtgd);
75
76 # Assumes that the mrtgc.csv file is in alpha order
77 open (DNSFILE,"<".$dnsfile);
78 $at = 0;
79 while(<DNSFILE>){
80 chomp;
81 $head = $_;
82 $sysn = lc((split /\,/,$head)[1]);
83 if ($sysn gt $mrtgd[$at]) {
84 while($at < @mrtgd) {
85 if($sysn le $mrtgd[++$at]){last; }
86 }
87 }
88 if (($sysn lt $mrtgd[$at]) || ($at >= @mrtgd)) {
89 #keep these lines
90 $mrtgc[@mrtgc] = $sysn;
91 $ovmrtgc[@ovmrtgc] = $head;
92 }
93 # }
94 }
95 close (DNSFILE);
96 #Now rebuild the mrtgc.csv file
97 open (DNSFILE,">".$dnsfile);
98 for ($cnt = 0 ; $cnt < @ovmrtgc ; ++$cnt){
99 print DNSFILE "$ovmrtgc[$cnt]\n";
100 }
101 close (DNSFILE);
102
103 #Build the index by keeping the original lines.
104 open (BUILDHT,"<".$buildhtf);
105 $head = 0;
106 $at = 0;
107 # This next piece of code assumes that the $buildhtf file is in alpha order
108 while(<BUILDHT>){
109 chomp;
110 if (/index (.*)\.cfg/){
111 $sysn = $1;
112 $head = $_;
113 if ($sysn gt $mrtgd[$at]) {
114 while($at < @mrtgd) {
115 if($sysn le $mrtgd[++$at]){last; }
116 }
117 }
118 if (($sysn lt $mrtgd[$at]) || ($at >= @mrtgd)) {
119 $buildhtt[@buildhtt] = $head;
120 }
121 }
122 }
123 close (BUILDHT);
124 open (BUILDHT,">".$buildhtf);
125 print BUILDHT <<ECHO;
126 #This file builds the HTML for each device being monitored
127 cd $rundir
128 ECHO
129 for ($cnt = 0; $cnt < @buildhtt ; $cnt++){
130 print BUILDHT "$buildhtt[$cnt]\n";
131 }
132 close (BUILDHT);
133
134 @mrtgc = sort(@mrtgc);
135 open (HTMLF,">".$webdir.$roothtml);
136 print HTMLF <<ECHO;
137 <HTML>
138 </HEAD>
139 <BODY BGCOLOR="#ffffff">
140 <CENTER><H1>$company Router MRTG Traffic Analysis </H1></CENTER>
141
142 <SPACER TYPE=VERTICAL SIZE=4>
143 <CENTER><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=0>
144 <TR VALIGN=top>
145 <TD WIDTH=388 ALIGN="CENTER"><FONT FACE="Arial,Helvetica" SIZE=2>
146 ECHO
147 for ($cnt = 0; $cnt < @mrtgc ; $cnt++){
148 $sysn = $mrtgc[$cnt];
149 $sysnhtml = $sysn.".html";
150 print HTMLF "<A HREF=\"$sysn\/$sysnhtml\">$sysn<\/A><br>\n";
151 }
152 print HTMLF <<ECHO;
153 </FONT>
154 </TD>
155 </TABLE>
156 </BODY>
157 </HTML>
158 ECHO
159 close(HTMLF);
160 open (MRTGC,">".$cronfile);
161 print MRTGC <<ECHO;
162 #This file runs the MRTG for each config /opt/mrtg/run/file
163 cd /opt/mrtg/run
164 ECHO
165 for ($cnt = 0; $cnt < @mrtgc ; $cnt++){
166 print MRTGC "perl $rundir\/mrtg $mrtgc[$cnt].cfg $backgrnd\n";
167 }
168 print MRTGC <<ECHO;
169 # Additonal commands could go here! Under NT the next line will not return
170 $buildhtf
171 # End of rebuild ht file
172 ECHO
173 close (MRTGC);
174 # send to management station
175 # (local host unless run from a management console)
176 `ovevent "" .1.3.6.1.4.1.11.2.17.1.0.58916873 .1.3.6.1.4.1.11.2.17.2.1.0 Integer 14 .1.3.6.1.4.1.11.2.17.2.2.0 OctetString "$ENV{OVwSessionID}" .1.3.6.1.4.1.11.2.17.2.4.0 OctetString "OVMRTG Delete for @ARGV COMPLETED"`
177 }
178 main;
179 exit(0);
180