~ubuntu-branches/ubuntu/dapper/mon/dapper-security

« back to all changes in this revision

Viewing changes to mon.d/mon.monitor

  • Committer: Bazaar Package Importer
  • Author(s): Roderick Schertler
  • Date: 2001-09-15 08:46:38 UTC
  • Revision ID: james.westby@ubuntu.com-20010915084638-cm3jl93lnhp6cdwg
Tags: upstream-0.99.2
ImportĀ upstreamĀ versionĀ 0.99.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
#
 
3
# mon.monitor
 
4
#
 
5
# monitor mon server
 
6
#
 
7
# Jim Trocki
 
8
#
 
9
# $Id: mon.monitor 1.3 Sat, 30 Jun 2001 14:44:29 -0400 trockij $
 
10
use strict;
 
11
 
 
12
use English;
 
13
use Mon::Client;
 
14
use Getopt::Std;
 
15
 
 
16
my %opt;
 
17
getopts ('u:p:p:t:', \%opt);
 
18
 
 
19
my @failures;
 
20
my @details;
 
21
 
 
22
my $TIMEOUT = 30;
 
23
 
 
24
$TIMEOUT = $opt{"t"} if ($opt{"t"});
 
25
 
 
26
foreach my $host (@ARGV)
 
27
{
 
28
    my $c = new Mon::Client (
 
29
        "host"          => $host,
 
30
    );
 
31
 
 
32
    if ($opt{"p"})
 
33
    {
 
34
        $c->port ($opt{"p"});
 
35
    }
 
36
 
 
37
    eval {
 
38
        local $SIG{"ALRM"} = sub { die "Timeout Alarm" };
 
39
        alarm $TIMEOUT;
 
40
 
 
41
        if (!defined $c->connect)
 
42
        {
 
43
            push @failures, $host;
 
44
            push @details, "$host: " . $c->error;
 
45
            undef $c;
 
46
            next;
 
47
        }
 
48
 
 
49
        if ($opt{"u"} && $opt{"p"})
 
50
        {
 
51
            if (! defined $c->login (
 
52
                    "username"  => $opt{"u"},
 
53
                    "password"  => $opt{"p"},
 
54
                ))
 
55
            {
 
56
                push @failures, $host;
 
57
                push @details, "$host: " . $c->error;
 
58
                undef $c;
 
59
                next;
 
60
            }
 
61
        }
 
62
 
 
63
        my @st = $c->list_state;
 
64
 
 
65
        if ($c->error ne "")
 
66
        {
 
67
            push @failures, $host;
 
68
            push @details, "$host: " . $c->error;
 
69
            $c->disconnect;
 
70
            undef $c;
 
71
            next;
 
72
        }
 
73
 
 
74
        push @details, "$host: @st";
 
75
 
 
76
        if (!defined $c->disconnect)
 
77
        {
 
78
            push @failures, $host;
 
79
            push @details, "$host: could not disconnect, " . $c->error;
 
80
            undef $c;
 
81
            next;
 
82
        }
 
83
 
 
84
        undef $c;
 
85
    };
 
86
 
 
87
    if ($EVAL_ERROR =~ "Timeout Alarm")
 
88
    {
 
89
        push @failures, $host;
 
90
        push @details, "$host: timeout";
 
91
    }
 
92
}
 
93
 
 
94
if (@failures)
 
95
{
 
96
    print join (" ", sort @failures), "\n";
 
97
}
 
98
 
 
99
else
 
100
{
 
101
    print "no failures\n";
 
102
}
 
103
 
 
104
if (@details)
 
105
{
 
106
    print join ("\n", @details), "\n";
 
107
}
 
108
 
 
109
if (@failures)
 
110
{
 
111
    exit 1;
 
112
}
 
113
 
 
114
exit 0;