File: mon.monitor

package info (click to toggle)
mon 0.99.2-9%2Betch2
  • links: PTS
  • area: main
  • in suites: etch
  • size: 908 kB
  • ctags: 299
  • sloc: perl: 9,801; ansic: 778; sh: 372; makefile: 122
file content (114 lines) | stat: -rwxr-xr-x 1,613 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/perl
#
# mon.monitor
#
# monitor mon server
#
# Jim Trocki
#
# $Id: mon.monitor 1.3 Sat, 30 Jun 2001 14:44:29 -0400 trockij $
use strict;

use English;
use Mon::Client;
use Getopt::Std;

my %opt;
getopts ('u:p:p:t:', \%opt);

my @failures;
my @details;

my $TIMEOUT = 30;

$TIMEOUT = $opt{"t"} if ($opt{"t"});

foreach my $host (@ARGV)
{
    my $c = new Mon::Client (
    	"host"		=> $host,
    );

    if ($opt{"p"})
    {
    	$c->port ($opt{"p"});
    }

    eval {
    	local $SIG{"ALRM"} = sub { die "Timeout Alarm" };
	alarm $TIMEOUT;

	if (!defined $c->connect)
	{
	    push @failures, $host;
	    push @details, "$host: " . $c->error;
	    undef $c;
	    next;
	}

	if ($opt{"u"} && $opt{"p"})
	{
	    if (! defined $c->login (
		    "username"	=> $opt{"u"},
		    "password"	=> $opt{"p"},
		))
	    {
		push @failures, $host;
		push @details, "$host: " . $c->error;
		undef $c;
		next;
	    }
	}

	my @st = $c->list_state;

	if ($c->error ne "")
	{
	    push @failures, $host;
	    push @details, "$host: " . $c->error;
	    $c->disconnect;
	    undef $c;
	    next;
	}

	push @details, "$host: @st";

	if (!defined $c->disconnect)
	{
	    push @failures, $host;
	    push @details, "$host: could not disconnect, " . $c->error;
	    undef $c;
	    next;
	}

	undef $c;
    };

    if ($EVAL_ERROR =~ "Timeout Alarm")
    {
    	push @failures, $host;
	push @details, "$host: timeout";
    }
}

if (@failures)
{
    print join (" ", sort @failures), "\n";
}

else
{
    print "no failures\n";
}

if (@details)
{
    print join ("\n", @details), "\n";
}

if (@failures)
{
    exit 1;
}

exit 0;