This script is designed for Debian Linux based 3CX deployments that need to be monitored in PRTG.
Create the scripts in
/var/prtg/scripts
Call the script: 3cxstatuscheck.pl
Make it executable:
chmod +x 3cxstatuscheck.pl
Edit using nano:
#!/usr/bin/perl
#
#
#Script which checks several things on a linux box and then reports back to PRTG
#
$message = "3CX DNS resolve services and logfile OK ";
$status = "0";
@services = ("3CXAudioProvider01","3CXCfgServ01","3CXEventNotificationManager","3CXIVR01","3CXMediaServer","3CXPhoneSystem01","3CXPhoneSystemMC01","3CXQueueManager01","3CXSystemService01","3CXTunnel01");
# Get information from PING about DNS lookupability
open(DNS, "nslookup www.cisco.com|");
@dnsout = <DNS>;
close(DNS);
if ($dnsout[3] =~ m/can't find/)
{
$message = "Unable to resolve DNS";
$status = "1";
}
#check all of the services
foreach $service (@services)
{
open(SERVICECHK, "systemctl status $service|");
@servicestatus = <SERVICECHK>;
close(SERVICECHK);
# print "\n $servicestatus[2] \n";
if ($servicestatus[2] =~ m/running/)
{
#this service is active
}
else
{
#something is wrong with this service
$status = "1";
$message = "One or more 3CX services currently not running";
}
}
#check the end of the log file
open(LOGCHK, "tail -n 500 /var/lib/3cxpbx/Data/Logs/3CXMediaServer* |grep Error|");
@logstatus = <LOGCHK>;
close(LOGCHK);
if ($logstatus[3] =~ m/Error/)
{
#something is wrong with this service
$status = "1";
$message = "3CX Logfile contains many recent errors";
}
if ($status eq '0')
{
print "0:0:3CX OK: $message";
}
else
{
print "2:2:3CX DEGRADED: $message";
}
Add to PRTG as an SSH script sensor.