summaryrefslogtreecommitdiff
path: root/puppet/modules/nagios/files/irc_bot/riseup-nagios-client.pl
blob: 2467058d45f1dcebb918d996f9a7719504e705a8 (plain)
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
#!/usr/bin/perl -w

# ##############################################################################
# Infrabot-Client - a simple Infrabot client which sends it's whole command
# line arguments to a local UNIX domain socket.
# ##############################################################################

use strict;
use IO::Socket;


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# >> CONFIGURATION >>

# Read a configuration file
#   The arg can be a relative or full path, or
#   it can be a file located somewhere in @INC.
sub ReadCfg
{
    my $file = $_[0];

    our $err;

    {   # Put config data into a separate namespace
        package CFG;

        # Process the contents of the config file
        my $rc = do($file);

        # Check for errors
        if ($@) {
            $::err = "ERROR: Failure compiling '$file' - $@";
        } elsif (! defined($rc)) {
            $::err = "ERROR: Failure reading '$file' - $!";
        } elsif (! $rc) {
            $::err = "ERROR: Failure processing '$file'";
        }
    }

    return ($err);
}

# Get our configuration information
if (my $err = ReadCfg('/etc/nagios_nsa.cfg')) {
    print(STDERR $err, "\n");
    exit(1);
}

# << CONFIGURATION <<
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

if (@ARGV == 0) {
	print "Hey - specify a message, sucker!\n";
	exit(1);
}

unless (-S $CFG::Nsa{'socket'}) {
	die "Socket '$CFG::Nsa{'socket'}' doesn't exist or isn't a socket!\n";
}

unless (-r $CFG::Nsa{'socket'}) {
	die "Socket '$CFG::Nsa{'socket'}' can't be read!\n";
}

my $sock = IO::Socket::UNIX->new (
	Peer    => $CFG::Nsa{'socket'},
	Type    => SOCK_DGRAM,
	Timeout => 10
) || die "Can't open socket '$CFG::Nsa{'socket'}'!\n";

print $sock "@ARGV";
close($sock);