����JFIF��x�x����'
| Server IP : 78.140.185.180 / Your IP : 216.73.216.170 Web Server : LiteSpeed System : Linux cpanel13.v.fozzy.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64 User : builderbox ( 1072) PHP Version : 7.3.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/self/root/proc/self/root/proc/1630575/root/usr/lib64/nagios/plugins/extra/ |
Upload File : |
#!/usr/bin/env perl
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request::Common;
use Net::DNS::Resolver;
use URI;
use JSON::XS;
use Getopt::Std;
use Netbox::Client;
use Net::Subnet qw(subnet_matcher);
use feature qw(say);
binmode( STDOUT, 'encoding(UTF-8)' );
my $status = 0;
my %opts;
getopts( 'u:p:h:t:', \%opts );
my @incidents;
if ( !$opts{u} || !$opts{p} || !$opts{h} ) {
say STDERR "Wrong usage, login credentials are not set up!";
exit 3;
}
$opts{t} //= 30;
my $list = get_urls( $opts{u}, $opts{p}, $opts{h}, $opts{t} );
my $cli = Netbox::Client->new();
my @nets
= map { $_->{prefix} } $cli->get( '/ipam/prefixes/?role=external&role=internal&role=shared&role=solusvm&tenant=fozzy&limit=999' )->{results}->@*;
if (!@nets) {
say STDERR "CRITICAL: Cannot obtain list of nets!";
exit 2;
}
my $our_nets = subnet_matcher @nets;
for my $hash (@$list) {
my $url = (%$hash)[0];
my $u = URI->new($url);
my $domain = $u->host || next;
my $records = get_records($domain) || next;
my $dns = check_fozzy_dns($domain);
next if ( ( !grep { $our_nets->($_) } @$records) && (!$dns) );
my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 } );
$ua->timeout( $opts{t} );
my $req = HTTP::Request->new( GET => $url );
my $res = $ua->request($req);
my $code = $res->code;
if ( $res->is_success || ( $code != 403 && $code != 404 ) ) {
if ( $res->previous ) {
next if $res->request->uri =~ /cgi-sys\/suspendedpage.cgi$/;
}
push @incidents, "$url returns $code code";
$status = 2;
}
}
if (@incidents) {
say "CRITICAL: $_" for @incidents;
}
else {
say 'OK';
}
exit $status;
# subs
sub get_urls {
my ( $user, $pass, $host, $timeout ) = @_;
my $ua = LWP::UserAgent->new();
$ua->timeout($timeout);
my $req = HTTP::Request->new( GET => $host );
$req->header( 'accept' => 'application/json' );
$req->header( 'content-type' => 'application/json' );
$req->authorization_basic( $user, $pass );
my $res = $ua->request($req);
if ( !$res->is_success ) {
say STDERR "CRITICAL: Cannot obtain list of URLs!";
exit 2;
}
else {
my $decoded = decode_json( $res->content )->{content};
return $decoded;
}
}
sub get_records {
my $domain = shift;
my @records;
my $dns = Net::DNS::Resolver->new;
my $reply = $dns->query( $domain, 'A' );
if ($reply) {
for my $rr ( $reply->answer ) {
push @records, $rr->address if $rr->type eq "A";
}
}
else {
return;
}
return \@records;
}
sub check_fozzy_dns {
my $domain = shift;
my $dns = Net::DNS::Resolver->new;
$dns->tcp_timeout(5);
$dns->udp_timeout(5);
$dns->nameservers(
'ns1.fozzy.com', 'ns2.fozzy.com',
'ns5.fozzy.com', 'ns6.fozzy.com',
'ns7.fozzy.com', 'ns8.fozzy.com'
);
my $reply = $dns->query( $domain, 'SOA' );
if ($reply) {
for my $rr ($reply) {
return 1 if ( $rr->string =~ /fozzy.com/i );
}
}
return;
}