]> git.somenet.org - root/munin.git/blob - cron/ircstats.pl
Added copyright + licence headers to my own code
[root/munin.git] / cron / ircstats.pl
1 #!/usr/bin/perl
2 #
3 # Copyright 2011 by Jan Vales <jan@jvales.net> (Someone <someone@somenet.org>)
4 #
5 #    This program is free software: you can redistribute it and/or modify
6 #    it under the terms of the GNU General Public License as published by
7 #    the Free Software Foundation, version 3 of the License.
8 #
9 #    This program is distributed in the hope that it will be useful,
10 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #    GNU General Public License for more details.
13 #
14 #    You should have received a copy of the GNU General Public License
15 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 #
17
18 require Net::IRC;
19
20 mkdir("/tmp/irc", 0775);
21 open (STATS, '>/tmp/irc/stats.txt');
22 open (CHANS, '>/tmp/irc/channels.txt');
23 my $irc = new Net::IRC;
24 my $conn = $irc->newconn(Nick => 'srv254-stats', Server => 'localhost');
25 $conn->debug(0);
26 $conn->add_global_handler('luserclient', \&luserclient);
27 $conn->add_global_handler('luserchannels', \&luserchannels);
28 $conn->add_global_handler('endofmotd', \&ask);
29 $conn->add_global_handler('list', \&list);
30 $conn->add_global_handler('listend', \&quit);
31
32
33 sub luserclient {
34     my($self, $event) = @_;
35     if(($event->args)[1] =~  /There are (\d+) users and (\d+) invisible on (\d+) servers/) {
36 #        printf STATS "".(($event->args)[1])."\n";
37         printf STATS "clients.value ".($1 + $2 -1)."\n";
38         printf STATS "servers.value $3\n";
39     }
40 }
41
42 sub luserchannels {
43     my($self, $event) = @_;
44     if(($event->args)[1] =~  /^(\d+)/) {
45         printf STATS "channels.value $1\n";
46     }
47 }
48
49 sub ask {
50     my($self, $event) = @_;
51     $conn->list();
52 }
53
54 sub list {
55     my($self, $event) = @_;
56     printf CHANS (($event->args)[1])." ".(($event->args)[2])." ".(($event->args)[3])."\n";
57 }
58
59 sub quit {
60     my($self, $event) = @_;
61     $self->quit();
62     close (STATS);
63     close (CHANS);
64     exit 0;
65 }
66
67
68
69 while(1) {
70     $irc->do_one_loop();
71 }
72