]> git.somenet.org - root/munin.git/blob - cron/ircstats.pl
muninplugins moved out of private root scripts
[root/munin.git] / cron / ircstats.pl
1 #!/usr/bin/perl
2 require Net::IRC;
3
4 mkdir("/tmp/irc", 0775);
5 open (STATS, '>/tmp/irc/stats.txt');
6 open (CHANS, '>/tmp/irc/channels.txt');
7 my $irc = new Net::IRC;
8 my $conn = $irc->newconn(Nick => 'srv254-stats', Server => 'localhost');
9 $conn->debug(0);
10 $conn->add_global_handler('luserclient', \&luserclient);
11 $conn->add_global_handler('luserchannels', \&luserchannels);
12 $conn->add_global_handler('endofmotd', \&ask);
13 $conn->add_global_handler('list', \&list);
14 $conn->add_global_handler('listend', \&quit);
15
16
17 sub luserclient {
18     my($self, $event) = @_;
19     if(($event->args)[1] =~  /There are (\d+) users and (\d+) invisible on (\d+) servers/) {
20 #        printf STATS "".(($event->args)[1])."\n";
21         printf STATS "clients.value ".($1 + $2 -1)."\n";
22         printf STATS "servers.value $3\n";
23     }
24 }
25
26 sub luserchannels {
27     my($self, $event) = @_;
28     if(($event->args)[1] =~  /^(\d+)/) {
29         printf STATS "channels.value $1\n";
30     }
31 }
32
33 sub ask {
34     my($self, $event) = @_;
35     $conn->list();
36 }
37
38 sub list {
39     my($self, $event) = @_;
40     printf CHANS (($event->args)[1])." ".(($event->args)[2])." ".(($event->args)[3])."\n";
41 }
42
43 sub quit {
44     my($self, $event) = @_;
45     $self->quit();
46     close (STATS);
47     close (CHANS);
48     exit 0;
49 }
50
51
52
53 while(1) {
54     $irc->do_one_loop();
55 }
56