File: ircu.in

package info (click to toggle)
munin 1.2.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,940 kB
  • ctags: 98
  • sloc: sh: 4,215; makefile: 452; perl: 135
file content (99 lines) | stat: -rwxr-xr-x 2,115 bytes parent folder | download | duplicates (3)
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
#!@@PERL@@
#
# $Log$
# Revision 1.1  2004/01/02 18:50:00  jimmyo
# Renamed occurrances of lrrd -> munin
#
# Revision 1.1.1.1  2004/01/02 15:18:07  jimmyo
# Import of LRRD CVS tree after renaming to Munin
#
# Revision 1.3  2003/12/18 19:02:36  jimmyo
# Typo
#
# Revision 1.2  2003/12/18 17:14:24  jimmyo
# Added autoconf-support
#
# Revision 1.1  2003/11/10 18:51:50  jimmyo
# Initial entries
#
#%# family=manual
#%# capabilities=autoconf

my $ret = undef;

if (! eval "require Net::IRC;")
{
    $ret = "Net::IRC not found";
}

if ($ARGV[0] and $ARGV[0] eq "autoconf")
{
    if ($ret)
    {
	print "no ($ret)\n";
	exit 1;
    }
    my $irc = new Net::IRC;
    my $conn;

    $irc = new Net::IRC; $conn = $irc->newconn(Nick => 'munin-ircd', Server => 'localhost');
    if (!$conn)
    {
	print "no (Couldn't connect to IRC server)\n";
	exit 1;
    }
    print "yes\n";
    exit 0;
}

if($ARGV[0] and $ARGV[0] eq "config") {
    print "host_name $ENV{FQDN}\n";
    print "graph_title ircd status\n";
    print "graph_order clients channels\n";
    print "graph_args -l 0\n";
    print "clients.label clients\n";
    print "clients.draw LINE2\n";
    print "channels.label channels\n";
    print "channels.draw LINE2\n";
    exit 0;
}

my $irc = new Net::IRC;
my $conn = $irc->newconn(Nick => 'munin-ircd',
			 Server => 'localhost');

my %result;
#$conn->debug(0);

sub luserclient {
    my($self, $event) = @_;
    if(($event->args)[1] =~  /There are (\d+) users and (\d+) invisible/) {
	$result{'clients'} = $1 + $2 - 1; # don't count this script
    }
}

sub luserchannels {
    my($self, $event) = @_;
    if(($event->args)[1] =~  /^(\d+)/) {
	$result{'channels'} = $1;
    }
}

sub quit {
    my($self, $event) = @_;
    open(STDERR, ">/dev/null");
    $self->quit();
    print "clients.value " . $result{'clients'} . "\n";
    print "channels.value " . $result{'channels'} . "\n";
}

$conn->add_global_handler('endofmotd', \&quit);
$conn->add_global_handler('luserclient', \&luserclient);
$conn->add_global_handler('luserchannels', \&luserchannels);


while(1) {
    $irc->do_one_loop();
}		 

# vim:syntax=perl