-
Notifications
You must be signed in to change notification settings - Fork 11
/
nsca-receive-http.cgi
70 lines (56 loc) · 1.36 KB
/
nsca-receive-http.cgi
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
#!/usr/bin/perl
# © 2019 -- Sig-I/O Automatisering -- Mark Janssen
# 2019/06/24: Version 1.0 -- MIT Licensed
# Process posted NSCA results from send_nsca_http_post, and forward them
# to the nagios.cmd / icinga.cmd socket
use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
sub output_top($);
sub output_error($);
sub output_end($);
sub process_data($);
my $q = new CGI;
print $q->header();
output_top($q);
if ($q->param()) {
process_data($q);
}
output_end($q);
exit 0;
# Outputs the start html tag, stylesheet and heading
sub output_top($) {
my ($q) = @_;
print $q->start_html();
}
sub output_error($) {
my ($q) = @_;
print $q->div("Access Denied");
print $q->end_html;
}
# Outputs a footer line and end html tags
sub output_end($) {
my ($q) = @_;
print $q->end_html;
}
# Displays the results of the form
sub process_data($) {
my ($q) = @_;
my $hname = $q->param('hostname');
my $cname = $q->param('checkname');
my $res = $q->param('retval');
my $edata = $q->param('extradata');
my $now = time();
# Limit checks to some specific domain
if ( $hname =~ /some\.subdomain\.tld/ )
{
open(my $fh, '>>', '/var/lib/icinga/rw/icinga.cmd');
print $fh "[$now] PROCESS_SERVICE_CHECK_RESULT;$hname;$cname;$res;$edata\n";
close $fh;
}
else
{
output_error($q);
}
}