1
#!/usr/local/bin/perl -w
8
$mibident=".ERRORNAME";
9
$miberrflag=".ERRORFLAG";
10
$miberrmsg=".ERRORMSG";
12
$mibheadall=".EXTENSIBLEDOTMIB";
13
$mibclearcache="$mibheadall.VERSIONMIBNUM.VERCLEARCACHE";
14
$mibrestartagent="$mibheadall.VERSIONMIBNUM.VERRESTARTAGENT";
15
$mibupdateconfig="$mibheadall.VERSIONMIBNUM.VERUPDATECONFIG";
16
%miblist=( '.PROCMIBNUM.1' => 'processes',
17
'.SHELLMIBNUM.1' => 'scripts',
18
'.MEMMIBNUM' => 'swap space',
19
'.DISKMIBNUM.1' => 'disks',
20
'.LOADAVEMIBNUM.1' => 'load-average',
21
'.ERRORMIBNUM' => 'snmp-agent-errors');
22
@fixitlist=('.PROCMIBNUM.1','.SHELLMIBNUM.1');
23
%mibchecklist = ('.PROCMIBNUM.1' => 1,
24
'.SHELLMIBNUM.1' => 1,
27
'.LOADAVEMIBNUM.1' => 1,
29
$errlog="/net/tyfon/1/OV/log/ece-log";
30
$default_get_args = "-v 1 %s private";
31
$default_set_args = "-v 1 %s private";
35
$fixit=0; # this should be 0 not -1, but is necissary till getc(STDIN) works
37
$display = $ENV{'DISPLAY'};
41
$logwindowatstart = 0;
47
# Mib Package: Each mib has a mib number attached and can check/fix itself;
57
$self->{'HostId'} = shift;
58
$self->{'Host'} = $self->{'HostId'}->{'Name'};
62
($self->{'MibSuffix'}) = /(\.[0-9]+)$/;
63
if (!defined($mibchecklist{$self->{'MibSuffix'}})) {
64
($self->{'MibSuffix'}) = /(\.[0-9]+\.1)$/;
66
print "suff: $self->{'MibSuffix'}\n";
67
$self->{'MibDesc'} = shift;
68
$self->{'Frame'} = shift;
74
return ($self->{'Mib'});
79
$self->{'Frame'}->toplevel->Busy() if ($::display);
81
my $cmd = "$::snmppath/snmpwalk " . sprintf($::default_get_args, $self->{'Host'}) . " $mib|";
82
::addToLog("running: $cmd",5);
87
$result[$outcount] = $_;
89
::addToLog("snmpwalk: $_",5);
91
$self->{'Frame'}->toplevel->update;
96
for($i=0; $i <= $#result; $i++) {
97
$result[$i] =~ s/ Hex:.*$//g;
98
$result[$i] =~ s/\"//g;
100
$self->{'Frame'}->toplevel->Unbusy() if ($::display);
101
if ($result[0] =~ /No Response/) {
102
$self->{'HostId'}->hostdown;
111
if ($::mibchecklist{$self->{'MibSuffix'}} != 1) {
115
printf "%sChecking %s: %s\r", $::eraseline,$self->{'Host'},
118
my @walkout = $self->snmp_walk("$self->{'Mib'}$::miberrflag");
119
while ($#walkout > -1) {
121
($result) = /= ([0-9]+)/;
122
if (defined($result) && $result > 0)
124
($mibloc) = /\.([0-9]+) /;
125
push(@{$tmp},FixProblem::new("",$self->{'HostId'}, $self->{'Mib'},
127
$mibloc,$self->{'Frame'}));
129
printf("%s%-8.8s %-12.12s %2d -- %-37.37s",$::eraseline,
130
$self->{'Host'},$tmp->[0]->{'ErrName'},
131
$result,$tmp->[0]->{'ErrMsg'});
132
if ($tmp->[0]->canfix() && $::fixit == 0) {
134
$ans = Term::ReadKey::ReadKey(0);
135
if ("$ans" eq "y" || "$ans" eq "Y") {
136
printf("\b\b\b\b\b\b\b\b");
137
$tmp->[0]->fix($mibloc); # fix now if curses
140
printf("\nChecking %s: %s\r",$self->{'Host'},
143
} elsif ($::fixit > 0) {
144
$tmp->[0]->fix($mibloc); # fix now if curses
154
# Problem Package: A problem comes into existence when found. It may
155
# or may not know how to fix itself (Problem/FixProblem).
164
$self->{'Frame'}->toplevel->Busy() if ($::display);
166
my $args = sprintf($::default_get_args, $self->{'Host'});
167
$_ = `$::snmppath/snmpget $args $mib`;
168
my ($result) = /= (.*)$/;
169
if (!defined($result) || $result =~ /No Response/) {
170
$self->{'HostId'}->hostdown;
174
$result =~ s/ Hex:.*$//g;
175
::addToLog("snmpget: $_",5);
176
$self->{'Frame'}->toplevel->Unbusy() if ($::display);
182
$self->{'Frame'}->toplevel->Busy() if ($::display);
184
my $args = sprint($::default_set_args, $self->{'Host'});
185
$_ = `$::snmppath/snmpset $args $mib`;
186
my ($result) = /= (.*)$/;
187
$result = "" if (!defined($result));
189
::addToLog("snmpset: $_",5);
190
$self->{'Frame'}->toplevel->Unbusy() if ($::display);
199
my $self = new Mib ($hostId,$mib,$mibname);
200
$self->{'MibLocation'} = shift;
203
$self->{'Frame'} = $tmp->Frame();
207
$self->snmp_get("$self->{'Mib'}$::mibident.$self->{'MibLocation'}");
209
$self->snmp_get("$self->{'Mib'}$::miberrmsg.$self->{'MibLocation'}");
210
if (exists $self->{'HostId'}->{'Down'}) {
214
$self->{'Frame'}->pack();
216
$self->{'Frame'}->Button(-text => sprintf("%-12.12s %-42.42s",
220
-highlightcolor => "#ffffff",
223
-bd => 0, -padx => 0, -pady => 0,
224
-activeforeground => 'red',
225
-activebackground => '#C9C9C9',
226
-background => '#E0C9C9',
227
-command => [\&selectme,$self]);
228
$self->{'Desc'}->pack(-fill => "x",-expand => 1,-side=>"left"); #
230
$tmp->toplevel->deiconify();
231
$tmp->toplevel->raise();
233
::addToLog("problem found: $self->{'Host'}\t$self->{'ErrName'}\t$self->{'ErrMsg'}",2);
241
$self->{'Desc'}->configure(-background => '#C9C9C9');
250
if (exists $self->{'Selected'}) {
251
main::deselectitem($self);
252
delete $self->{'Selected'};
254
main::selectitem($self);
255
$self->{'Desc'}->configure(-foreground => "red");
256
$self->{'Selected'} = 1;
263
$self->{'Desc'}->configure(-foreground => "black");
264
delete $self->{'Selected'};
270
main::setstatus("Checking $self->{'Host'} -- $self->{'ErrName'}");
273
printf("Checking \b\b\b\b\b\b\b\b\b");
275
$result = $self->snmp_get("$self->{'Mib'}$::miberrflag.$self->{'MibLocation'}");
276
if (exists $self->{'HostId'}->{'Down'}) {
282
main::setstatus("idle");
287
# Don't fix and/or unable to
289
main::setmsg("Don't know how to fix $self->{'ErrName'}");
295
system "xterm -e rsh $self->{'HostId'}->{'Name'} -l root &";
301
my $host = $self->{'HostId'};
302
$host->deleteProb($self);
308
if ($self->{'Selected'}) {
309
main::deselectitem($self);
311
$self->{'Desc'}->destroy();
312
$self->{'Frame'}->destroy();
322
@ISA = qw( Problem );
331
my $self = new Problem ($hostId,$mib,$mibdesc,$mibloc,$frame);
333
($mymib) = /(\.[0-9]+)$/;
334
if (grep(/$mymib/,@::fixitlist) && ($::fixit >= 0)) {
335
bless $self; # Make it a FixProblem if fixable
337
return $self; # else just return a Problem
348
main::setstatus(sprintf("Fixing %s: %s",
349
$self->{'Host'}, $self->{'ErrName'}));
352
printf(" / Fixing...\b\b\b\b\b\b\b\b\b");
354
$self->snmp_set("$self->{'Mib'}$::mibfix.$self->{'MibLocation'} integer 1");
355
$self->snmp_set("$::mibclearcache integer 1");
356
if (exists $self->{'HostId'}->{'Down'}) {
360
main::setstatus("Sleeping");
363
printf("Sleeping \b\b\b\b\b\b\b\b\b");
367
main::setstatus("Checking");
370
printf("Checking\b\b\b\b\b\b\b\b");
372
if ($self->check() != 0) {
374
printf("*failed* \n");
376
main::setmsg("Failed to fix $self->{'ErrName'} on $self->{'Host'}");
381
# $self->{'HostId'}->deleteProb($self);
382
main::setmsg("Fixed $self->{'ErrName'} on $self->{'Host'}");
388
main::setstatus("Idle");
392
# Host Package: Each object is a host which can check itself and display
399
($av) = /\.([0-9]+)/;
401
($bv) = /\.([0-9]+)/;
408
$self->{'Name'} = shift;
409
$self->{'Host'} = $self->{'Name'};
410
$self->{'Mibs'} = [];
411
$self->{'Problems'} = [];
414
$self->{'MainFrame'} = $::HostFrame->Frame();
416
$self->{'MainFrame'}->configure(-relief =>"sunken",-borderwidth=>2);
418
$self->{'ProbFrame'} = $self->{'MainFrame'}->Frame();
419
$self->{'hostlabel'} =
420
$self->{'MainFrame'}->Button(-text => sprintf("%-9.9s",
422
-bd => 0, -padx => 0, -pady => 0,
423
-command =>[\&selectme,$self],
424
-activeforeground => 'red',
425
-activebackground => '#C9C9C9',
429
$self->{'hostlabel'}->pack(-side=>"left",-ipadx=>1,
430
-padx=> 1,-pady =>1);
431
$self->{'ProbFrame'}->pack(-side=>"left",-ipadx=>1,
432
-padx=> 1,-pady =>1);
433
$self->{'MainFrame'}->pack( #-padx => 2,-pady =>2,
434
-fill => "x", -expand => 1);
436
foreach $mibx ( sort mibsort keys(%::miblist) ) {
437
push(@{$self->{'Mibs'}},
438
new Mib ($self,"$::mibheadall$mibx",$::miblist{$mibx},
439
$self->{'ProbFrame'}));
447
system "xterm -e rsh $self->{'Name'} -l root &";
457
if (exists $self->{'Selected'}) {
458
main::deselectitem($self);
459
delete $self->{'Selected'};
461
main::selectitem($self);
462
$self->{'hostlabel'}->configure(-foreground => "red");
463
$self->{'Selected'} = 1;
469
$self->{'hostlabel'}->configure(-foreground => "black");
470
delete $self->{'Selected'};
475
if (! exists $self->{'Down'}) {
476
foreach $i (@{$self->{'Problems'}}) {
477
if ($i->canfix() && ref($i) ne Host) {
486
foreach $i (@{$self->{'Problems'}}) {
487
if (ref($i) ne Host) {
499
$self->deleteProbs();
500
push(@{$self->{'Problems'}},$self);
503
if (!exists $self->{'hostlabel'}) {
504
$self->{'hostlabel'} =
505
$self->{'MainFrame'}->Button(-text => sprintf("%-9.9s",
507
-bd => 0, -padx => 0, -pady => 0,
508
-command =>[\&selectme,$self],
509
-activeforeground => 'red',
510
-activebackground => '#C9C9C9',
515
::addToLog("$self->{'Name'} is down",2);
516
$self->{'hostlabel'}->configure(-text =>
517
sprintf("%-9.9s down",$self->{'Name'}),
524
$self->{'noDelete'} = 1;
525
$self->deleteProbs();
526
delete $self->{'noDelete'};
528
$self->{'hostlabel'}->configure(-text => $self->{'Name'},-width=>9);
530
delete $self->{'Down'};
531
main::setstatus("pinging $self->{'Name'}");
532
if (!($::pinghost) || Net::Ping::pingecho($self->{'Name'},2)) {
533
foreach $i (@{$self->{'Mibs'}}) {
534
if (ref($i) ne Mib) {
535
print "$i is a ref($i) not a Mib\n";
537
main::setstatus("Checking $self->{'Name'}: " . $i->{'MibDesc'});
538
push(@{$self->{'Problems'}},$i->check());
540
if (exists $self->{'Down'}) {
547
main::setstatus("Idle");
548
if ($#{$self->{'Problems'}} == -1) {
555
if ($self->{'Selected'}) {
556
main::deselectitem($self);
558
$self->deleteProbs();
560
$self->{'hostlabel'}->destroy();
561
$self->{'ProbFrame'}->destroy();
562
my $top = $self->{'MainFrame'}->toplevel;
563
$self->{'MainFrame'}->destroy();
566
main::deletehost($self->{'Name'});
571
foreach $i (@{$self->{'Problems'}}) {
572
if (ref($i) eq Host) {
573
delete $self->{'Problems'};
576
if (ref($i) ne Problem && ref($i) ne FixProblem) {
577
print "i: $i is a ", ref($i), "\n";
580
$self->deleteProb($i);
587
for ($k = 0; $k <= $#{$self->{'Problems'}}; $k++) {
588
if (ref($self->{'Problems'}->[$k]) eq Problem ||
589
ref($self->{'Problems'}->[$k]) eq FixProblem ) {
590
if ($self->{'Problems'}->[$k]->{'Mib'} eq $child->{'Mib'} &&
591
$self->{'Problems'}->[$k]->{'MibLocation'} eq
592
$child->{'MibLocation'}) {
593
splice(@{$self->{'Problems'}},$k,1);
594
$child->deleteself();
595
if ($#{$self->{'Problems'}} == -1 &&
596
!exists $self->{'noDelete'}) {
602
print " not: ",$self->{'Problems'}->[$k],"/",
603
ref($self->{'Problems'}->[$k]),"\n";
615
while ($#ARGV >= 0 && $ARGV[0] =~ /^-/) {
617
$andlog = 1 if (/^-a/);
618
$dontstart = 1 if (/^-d/);
619
$fixit = -1 if (/^-n/);
620
$fixit = 1 if (/^-y/);
621
$display = 0 if (/^-x/);
622
$pinghost = 1 if (/^-p/);
623
$hidden = 1 if (/^-H/);
624
$loglevel = shift if (/^-V/);
625
$logwindowatstart = 1 if (/^-L/);
626
&display_help() if (/^-h/);
627
&setmibchecklist(@fixitlist) if (/^-f/);
632
# If necessary check the ece-log file for problems
635
if (($andlog || $#ARGV == -1) && !$dontstart) {
639
@tmp = grep(/$fields[0]/,@ARGV);
640
if ($#tmp == -1) { # && $fields[1] ne "down") {
641
$ARGV[$#ARGV + 1] = $fields[0];
648
# Check all the found hosts
653
# $tk_strictMotif = 1;
654
$top = MainWindow->new();
655
$top->bind('all',"<Control-q>",[\&quit]);
656
$top->bind('all',"<Control-h>",[\&makehidden]);
657
$top->bind('all',"<Control-s>",[\&seenall]);
658
$top->bind('all',"<Control-f>",[\&fixall]);
659
$top->option('add','*highlightThickness','0'); #wish this worked
660
# $top->option('add','*highlightbackground','#C9C9C9');
661
$top->option('add','*background','#C9C9C9');
662
$top->option('add','*font','6x13');
663
$HostFrame = $top->Frame();
664
$MenuFrame = $top->Frame(-relief => "raised",-borderwidth => 2);
665
$MenuFrame->pack(-fill => "x",-expand => 1);
666
$statusBar = $top->Frame(-relief => "raised",-borderwidth => 2);
667
$status = $statusBar->Label(-text => "initializing",-anchor =>"e");
668
$statusl = $statusBar->Label(-text => "Status: ", -anchor => "w");
669
$msgBar = $top->Frame(-relief => "raised",-borderwidth => 2);
670
$msg = $msgBar->Label(-text => "",-anchor =>"e");
671
$msgl = $msgBar->Label(-text => "Note: ", -anchor => "w");
673
$botFrame = $top->Frame();
674
$butFrame = $top->Frame();
676
$NewHost = $botFrame->Entry(-textvariable => \$entryhost,-width=>20,
677
-relief => "sunken");
678
$NewHost->bind("<Return>",sub {newHost("$entryhost");
679
$NewHost->delete(0,length($entryhost));});
680
$BotLabel = $botFrame->Label(-text => "Check New Host: ",
682
$CmdsMenuBut = $MenuFrame->Menubutton(-text => "Cmds");
683
$CmdsMenu = $CmdsMenuBut->Menu(-tearoff => 1);
684
$CmdsMenuBut->configure(-menu => $CmdsMenu);
685
$CmdsMenuBut->pack(-side => "left");
686
$CmdsMenuBut->command(-label => "Check Hosts", -command => [\&rescanhosts]);
687
$CmdsMenuBut->command(-label => "Check Log", -command => [\&scanlog]);
688
$CmdsMenuBut->command(-label => "Fix All", -command => [\&fixall],
689
-accelerator => "Ctrl-f");
690
$CmdsMenuBut->command(-label => "Seen All", -command => [\&seenall],
691
-accelerator => "Ctrl-s");
692
$CmdsMenuBut->separator();
693
$CmdsMenuBut->command(-label => "Hide", -command => [\&makehidden],
694
-accelerator => "Ctrl-h");
695
$CmdsMenuBut->command(-label => "Quit", -command => [\&quit],
696
-accelerator => "Ctrl-q");
697
$PrefsMenuBut = $MenuFrame->Menubutton(-text => "Prefs");
698
$PrefsMenu = $PrefsMenuBut->Menu(-tearoff => 1);
699
$PrefsMenuBut->configure(-menu => $PrefsMenu);
700
$PrefsMenuBut->pack(-side => "left");
701
$PrefsMenuBut->cascade(-label => "Rescan");
702
$RescanPrefsBut = $PrefsMenu->Menu();
703
$PrefsMenuBut->entryconfigure("Rescan",-menu => $RescanPrefsBut);
706
$afterId = Tk::after($rescanWhen*1000,[\&autorescan]);
708
$RescanPrefsBut->checkbutton(-label =>"Auto Rescan",
709
-variable =>\$AutoRescan,
710
-command => sub {if ($AutoRescan) {
712
Tk::after($rescanWhen*1000,[\&autorescan])
714
Tk::after("cancel",$afterId);
717
$RescanPrefsBut->checkbutton(-label =>"Checks Log",
718
-variable =>\$AutoCheckLog);
720
$RescanPrefsBut->checkbutton(-label =>"Checks Hosts",
721
-variable =>\$AutoCheckHosts);
722
$RescanWhenHidden = 1;
723
$RescanPrefsBut->checkbutton(-label =>"Only When Hidden",
724
-variable =>\$RescanWhenHidden);
726
$RescanPrefsBut->checkbutton(-label =>"Pop forward with new",
727
-variable =>\$raiseonnew);
729
$PrefsMenuBut->cascade(-label => "Log Verbosity");
730
$LogVerbBut = $PrefsMenu->Menu();
731
$PrefsMenuBut->entryconfigure("Log Verbosity",
732
-menu => $LogVerbBut);
733
for ($i=1; $i <= $numloglevels; $i++) {
734
$LogVerbBut->radiobutton(-label => "$i", -variable => \$loglevel,
738
$PrefsMenuBut->cascade(-label => "Check For");
739
$CheckForBut = $PrefsMenu->Menu();
740
$PrefsMenuBut->entryconfigure("Check For",
741
-menu => $CheckForBut);
742
$CheckForBut->command(-label => "Fixable Problems",
743
-command => [\&setmibchecklist,@fixitlist]);
744
$CheckForBut->command(-label => "Everything",
745
-command => [\&setmibchecklist,keys(%miblist)]);
746
$CheckForBut->separator();
747
foreach $i ( sort mibsort keys(%::mibchecklist) ) {
748
$CheckForBut->checkbutton(-label => $miblist{$i},
749
-variable => \$mibchecklist{$i});
752
$PrefsMenuBut->checkbutton(-label => "Ping Host First",
753
-variable => \$pinghost);
757
$agentMenuBut = $MenuFrame->Menubutton(-text => "Agent-Control");
758
$agentMenu = $agentMenuBut->Menu(-tearoff => 1);
759
$agentMenuBut->configure(-menu => $agentMenu);
760
$agentMenuBut->pack(-side => "left");
761
$agentMenuBut->command(-label => "Re-read Configuration",
762
-command => [sub {if ($selected) { $top->Busy();
763
my $args = sprint($::default_get_args, $selected->{'Host'});
764
$_ = `$::snmppath/snmpset $args $mibupdateconfig i 1`; $top->Unbusy();}}]);
765
$agentMenuBut->command(-label => "Clear Exec Cache",
766
-command => [sub {if ($selected) { $top->Busy();
767
my $args = sprint($::default_get_args, $selected->{'Host'});
768
$_ = `$::snmppath/snmpset $args $mibclearcache i 1`; $top->Unbusy();}}]);
769
$agentMenuBut->separator();
770
$agentMenuBut->command(-label => "Re-start Agent",
771
-command => [sub {if ($selected) { $top->Busy();
772
my $args = sprint($::default_get_args, $selected->{'Host'});
773
$_ = `$::snmppath/snmpset $args $mibrestartagent i 1`; $top->Unbusy();} }]);
775
# set up remote commands
777
$remoteMenuBut = $MenuFrame->Menubutton(-text => "Remote-Info");
778
$remoteMenu = $remoteMenuBut->Menu(-tearoff => 1);
779
$remoteMenuBut->configure(-menu => $remoteMenu);
780
$remoteMenuBut->pack(-side => "left");
781
$remoteMenuBut->command(-label => "Load-Av", -command => [\&remote_load]);
782
$remoteMenuBut->separator();
783
$remoteMenuBut->command(-label => "top", -command => [\&remote_cmd,"top"]);
784
$remoteMenuBut->command(-label => "mailq", -command => [\&remote_cmd,"mailq"]);
785
$remoteMenuBut->command(-label => "ps", -command => [\&remote_cmd,"ps"]);
786
$remoteMenuBut->command(-label => "conf", -command => [\&remote_cmd,"conf"]);
788
# set up log file menu
789
$logFileMenuBut = $MenuFrame->Menubutton(-text => "Log");
790
$logFileMenu = $logFileMenuBut->Menu(-tearoff => 1);
791
$logFileMenuBut->configure(-menu => $logFileMenu);
792
$logFileMenuBut->pack(-side => "left");
793
$logFileMenuBut->command(-label => "show log", -command => [\&displayLog]);
794
$logFileMenuBut->command(-label => "clear log", -command => [\&clearLog]);
795
$logFileMenuBut->separator();
796
$logFileMenuBut->command(-label => "show Tyfon's log", -command => [\&displayTyfon]);
801
$statusl->pack(-fill => "x", -expand => 1, -side =>"left");
802
$status->pack(-fill => "x", -expand => 1, -side =>"left");
803
$msgl->pack(-fill => "x", -expand => 1, -side => "left");
804
$msg->pack(-fill => "x", -expand => 1, -side => "left");
805
$statusBar->pack(-fill => "x", -expand => 1);
806
$msgBar->pack(-fill => "x", -expand => 1);
807
$HostFrame->pack(-fill => "x",-expand => 1);
808
$butFrame->pack(-fill => "x",-expand => 1);
809
$botFrame->pack(-fill => "x",-expand => 1);
810
$FixBut = $butFrame->Button(-text => "Fix",-command=>[sub{print "hi\n"}],
811
-state => "disabled");
812
$FixBut->pack(-side => "left",-padx => 4,-pady => 2,-ipadx => 2,
814
$RshBut = $butFrame->Button(-text => "Rsh",-command=>[sub{print "hi\n"}],
815
-state => "disabled");
816
$RshBut->pack(-side => "left",-padx => 4,-pady => 2,-ipadx => 2,
818
$DelBut = $butFrame->Button(-text => "Del",
819
-state => "disabled");
820
$DelBut->pack(-side => "left",-padx => 4,-pady => 2,-ipadx => 2,
822
$ChkBut = $butFrame->Button(-text => "Chk",
823
-state => "disabled");
824
$ChkBut->pack(-side => "left",-padx => 4,-pady => 2,-ipadx => 2,
826
$BotLabel->pack(-fill => "x",-expand => 1,-side=>"left");
827
$NewHost->pack(-side=>"left");
828
&makehidden() if ($hidden);
831
# generate log window, but tell it not to create display
832
$logwindow = MainWindow->new;
833
$logwindow->option('add','*highlightThickness','0'); #wish this worked
834
# $logwindow->option('add','*highlightbackground','#C9C9C9');
835
$logwindow->option('add','*background','#C9C9C9');
836
$logwindow->option('add','*font','6x13');
838
$logbuttons = $logwindow->Frame;
839
$logbuttons->pack(-side => 'bottom', -expand => 1, -fill => 'x');
840
$logclose = $logbuttons->Button(-text => 'Close',
841
-command => ['withdraw',$logwindow]);
842
$logclose->pack(-side => 'left', -expand => 1);
844
$logtext = $logwindow->Text(-height => 40, -setgrid => 1);
845
$logtext->pack(-side => 'left', -fill => 'both', -expand => 1);
846
$logscroll = $logwindow->Scrollbar(-command => ['yview',$logtext]);
847
$logscroll->pack(-side => 'right', -fill => 'y');
848
$logtext->configure(-yscrollcommand => ['set', $logscroll]);
849
$logwindow->title("snmpcheck Action Log file");
850
$logwindow->iconname("snmpcheck-log");
851
$logtext->delete('1.0','end');
852
$logclear = $logbuttons->Button(-text => 'Clear Log',
853
-command => [\&deleteLog]);
854
$logclear->pack(-side => 'right', -expand => 1);
855
if (! $logwindowatstart) {
856
$logwindow->withdraw;
859
$status->configure(-text => "Idle");
861
# fill table with hosts
871
Term::ReadKey::ReadMode(3);
874
printf("$eraseline");
879
foreach $host ( @hostlist ) {
886
if (!exists $chost{"$name"}) {
887
$chost{"$name"} = new Host ($name);
888
if ($::display) { $top->update(); }
889
$chost{"$name"}->check;
891
setmsg("$name all ready exists");
897
delete $chost{"$name"};
903
$status->configure(-text => $arg);
912
$msg->configure(-text => $arg);
921
my $logaddlevel = shift;
922
if (! defined($logaddlevel)) {
925
if ($logaddlevel <= $loglevel) {
926
$logtext->insert('end'," " x ($logaddlevel-1) . "$logmsg\n");
932
remote_cmd_generic("cat /net/tyfon/1/OV/log/ece-log","Tyfon -- ece-log");
936
$logwindow->deiconify;
941
$logtext->delete('1.0','end');
947
$FixBut->configure(-state => "disabled");
948
$RshBut->configure(-state => "disabled");
949
$DelBut->configure(-state => "disabled");
950
$ChkBut->configure(-state => "disabled");
956
$selected->deselectme();
959
if (ref($selected) ne Host || !(exists $selected->{'Down'})) {
960
$RshBut->configure(-state => "normal", -command => ['rsh',$selected]);
962
$RshBut->configure(-state => "disabled");
964
$DelBut->configure(-state => "normal", -command => ['deleteme',$selected]);
965
$ChkBut->configure(-state => "normal", -command => ['check',$selected]);
966
if ($selected->canfix() && !(exists $selected->{'Down'})) {
967
$FixBut->configure(-state => "normal",
968
-command => ['fix',$selected]);
970
$FixBut->configure(-state => "disabled");
978
$MenuFrame->pack("forget");
979
$statusBar->pack("forget");
980
$msgBar->pack("forget");
981
$butFrame->pack("forget");
982
$botFrame->pack("forget");
988
$HostFrame->pack("forget");
989
$MenuFrame->pack(-expand => 1, -fill => "x");
990
$statusBar->pack(-expand => 1, -fill => "x");
991
$msgBar->pack(-expand => 1, -fill => "x");
992
$HostFrame->pack(-expand => 1, -fill => "x");
993
$butFrame->pack(-expand => 1, -fill => "x");
994
$botFrame->pack(-expand => 1, -fill => "x");
1006
open(LOG,$::errlog);
1009
@tmp = grep(/$fields[0]/,@ARGV);
1010
if ($#tmp == -1 && !exists $::chost->{$fields[0]}) {
1011
newHost($fields[0]);
1018
foreach $i (keys(%chost)) {
1019
$chost{$i}->check();
1024
$afterId = Tk::after($rescanWhen*1000,[\&autorescan]);
1025
if ($RescanWhenHidden && !$hidden) {return;}
1026
if ($AutoCheckHosts) {
1029
if ($AutoCheckLog) {
1035
foreach $i (keys(%chost)) {
1036
$chost{$i}->{'MainFrame'}->configure(-relief => "flat",-borderwidth=>0);
1041
foreach $i (keys(%chost)) {
1042
$chost{$i}->{'MainFrame'}->configure(-relief =>"sunken",-borderwidth=>2);
1047
foreach $i (keys(%chost)) {
1053
foreach $i (keys(%chost)) {
1054
$chost{$i}->seenall();
1061
remote_cmd_generic("$::snmppath/rsnmp -p $type $selected->{'Host'}",
1062
"$selected->{'Host'} -- $type",1);
1064
setmsg("Error: Nothing selected");
1070
remote_cmd_generic("$::snmppath/snmpwalk " . sprintf($::default_get_args,$selected->{'Host'}) . " .EXTENSIBLEDOTMIB.LOADAVEMIBNUM.LOADAVE",
1071
"$selected->{'Host'} -- LoadAve");
1073
setmsg("Error: Nothing selected");
1077
sub remote_cmd_generic {
1081
addToLog("running: $cmd ... ");
1082
my $newwin = MainWindow->new;
1085
$newwin->option('add','*highlightThickness','0'); #wish this worked
1086
# $newwin->option('add','*highlightbackground','#C9C9C9');
1087
$newwin->option('add','*background','#C9C9C9');
1088
$newwin->option('add','*font','6x13');
1090
my $buttons = $newwin->Frame;
1091
$buttons->pack(-side => 'bottom', -expand => 1, -fill => 'x');
1092
my $entries = $newwin->Frame;
1093
$entries->pack(-side => 'bottom', -expand => 1, -fill => 'x');
1095
my $text = $newwin->Text(-height => 40, -setgrid => 1);
1096
$text->pack(-side => 'left', -fill => 'both', -expand => 1);
1097
my $scroll = $newwin->Scrollbar(-command => ['yview',$text]);
1098
$scroll->pack(-side => 'left', -fill => 'y');
1099
$text->configure(-yscrollcommand => ['set', $scroll]);
1101
my $close = $buttons->Button(-text => 'Close',
1102
-command => ['destroy',$newwin]);
1103
$close->pack(-side => 'left', -expand => 1);
1104
my $rerun = $buttons->Button(-text => 'Re-Run',
1105
-command=>[\&fill_text,'',$text,
1107
$rerun->pack(-side => 'left', -expand => 1);
1109
my $cmdlabel = $entries->Label(-text => "Command: ");
1110
my $cmdtexte = $entries->Entry(-textvariable => \$cmd,
1111
-relief => "sunken");
1112
$cmdtexte->bind('<Return>' => [\&fill_text,$text, \$cmd,$insert]);
1113
$cmdlabel->pack(-side => 'left');
1114
$cmdtexte->pack(-side => 'left');
1116
my $searchtext = '';
1117
my $searchlabel = $entries->Label(-text => "Search for: ");
1118
my $searchtexte = $entries->Entry(-textvariable => \$searchtext,
1119
-relief => "sunken");
1121
$searchtexte->pack(-side => 'right');
1122
$searchlabel->pack(-side => 'right');
1123
$searchtexte->bind('<Return>' => [sub { $text->tag('remove','search','0.0','end');
1124
my($current, $length) = ('1.0', 0);
1126
$current = $text->search(-count => \$length, $searchtext, $current, 'end');
1127
last if not $current;
1128
$text->tag('add', 'search', $current, "$current + $length char");
1129
$current = $text->index("$current + $length char");
1130
$text->tag('configure','search',
1134
if (defined($title)) {
1135
$newwin->title($title);
1136
$newwin->iconname($title);
1138
fill_text('',$text,\$cmd,$insert);
1146
$textw->delete('1.0','end');
1147
if (defined($insert) && $insert) {
1148
$textw->insert('end',"running: $$cmd\n\n");
1150
$textw->toplevel->update();
1151
$textw->toplevel->Busy();
1154
$textw->insert('end',$_);
1155
$textw->toplevel->update();
1156
$textw->toplevel->Busy();
1159
if (defined ($insert) && $insert) {
1160
$textw->insert('end',"\ndone.\n");
1162
$textw->toplevel->Unbusy();
1164
addToLog("done: $$cmd");
1169
Usage: snmpcheck [-x] [-n|y] [-h] [-H] [-V NUM] [-L] [-f] [[-a] HOSTS]
1171
-h\tDisplay this message.
1172
-a\tcheck error log file AND hosts specified on command line.
1173
-p\tDon't try and ping-echo the host first
1174
-f\tOnly check for things I can fix
1175
HOSTS\tcheck these hosts for problems.
1178
-x\tforces ascii base if \$DISPLAY set (instead of tk).
1179
-H\tstart in hidden mode. (hides user interface)
1180
-V NUM\tsets the initial verbosity level of the command log (def: 1)
1181
-L\tShow the log window at startup
1182
-d\tDon't start by checking anything. Just bring up the interface.
1185
-n\tDon't ever try and fix the problems found. Just list.
1186
-y\tAlways fix problems found.
1194
my $resource = shift;
1195
return $top->option('get',$resource);
1199
my $resource = shift;
1201
$top->option('add',"*$resource",$value);
1210
($av) = /\.([0-9]+)/;
1212
($bv) = /\.([0-9]+)/;
1216
sub setmibchecklist {
1218
foreach $i (keys(%mibchecklist)) {
1219
$mibchecklist{$i} = 0;
1222
$mibchecklist{$i} = 1;