Sending SMS Notifications from PRTG network monitor Using NetPing

  • Published In: Tutorial
  • Created Date: 2015-06-29
  • Hits: 4945

Devices with enhanced features and a built-in modem, such as a gateway for sending and receiving SMS commands NetPing SMS, a device for remote monitoring of sensors via a network UniPing server solution v4/SMS and a device for remote controlling power supply sockets NetPing 8/PWR-220 v4/SMS have got a feature of sending random SMS notifications using HTTP API. This innovation can be used in the monitoring system PRTG Network Monitor to send SMS notifications about certain events in monitoring objects. As a result of organizing such system of SMS notifications PRTG Network Monitor, it is possible to save some funds using alternate services for sending SMS notifications, available on the Internet.

Requirements

To implement a functionality described above, there is a need to have:

  • a gateway for sending and receiving SMS commands NetPing SMS with an installed SIM card, a device for remote sensors monitoring UniPing server solution v4/SMS or a device for remote controlling power supply sockets NetPing 8/PWR-220 v4/SMS  with an installed SIM card;
  • a prepared script on PowerShell for sending random SMS notifications about events in the monitoring system PRTG Network Monitor;
  • a configured monitoring system PRTG Network Monitor

PRTG Network Monitor Configuration

To configure SMS notifications in the monitoring system PRTG using HTTP API, there is a need to go to the tab «Setup» to adjust basic configuration of the system:

Basic settings of the PRTG Network Monitor system

Go to «Notifications» in the area «ACCOUNT SETTINGS» at the page of system settings of the system PRTG. All notifications are configured in «Notifications»:

Configuring notifications in the Notifications section of PRTG Network Monitor

The system will prompt to enter a system administrator's username and a password to get an access to the web page «Notifications»:

Authorization in PRTG Network monitor system

After a successful authorization, the table «NOTIFICATIONS» will appear, where a new notification should be added by clicking the button «Add new notification»:

Setting up a new notification for NOTIFICATIONS on the PRTG Network Monitor

At the page for configuring new notification «Add notification» indicate a notification name in the field «Notification Name», for example, «SMS Notification» and check the checkbox «EXECUTE PROGRAM». There is a need to fill in parameters in the configuration area «EXECUTE PROGRAM».

Configuring notifications by the Execute Program method in PRTG Network monitor

where:
Program File – choose a file to run from a drop-down list (particularly the script PowerShell for sending random SMS notifications in this case). PRTG will run this file each time when conditions for this notification to trigger will be fulfilled. To choose a previously prepared script, it needs to be located via the next path: "C:\Program Files (x86)\PRTG Network Monitor\Notifications\EXE". If the monitoring system PRTG consists of a cluster of servers, then executed file is necessary to be copied by represented path for each server in a cluster. This will prevent an issue of sending SMS notifications when one or several servers in a cluster are out of action.
Parameter – specify parameters that will be transmitted to the executed file when starting. For NetPing devices, there is a need to indicate a phone number in square brackets and an SMS text separated by a space to send SMS notification. In an SMS text, it is acceptable to use system variables of the PRTG Network Monitor. Kindly see a list of variables here.
Timeout – is time within which an operation of executed file will be interrupted if a process of executing a script has stuck.

After specifying all parameters of a new notification, there is a need to save settings by clicking the button «Save».

As a result, a new notification will appear in the table «Notification»:

Notification list on the PRTG Notifications page

For a created SMS notification to work properly, it must be applied to necessary sensors or devices in the system PRTG.

Let us consider the example of using SMS notification, which will be triggered when a device disappears or appears in a local network. To do this, there is a need to choose a necessary device in the PRTG, which is checked for accessibility by the command «Ping». The choice is made at the page «Devices»:

Main menu of PRTG monitoring system

Just for an example, let us pick the device «Mail Server» out of the list of devices configured for monitoring at the page «Devices». A choice is made by clicking a mouse pointer on the name of a device:

List of PRTG monitoring system devices

The page «Device Mail Server» will be opened, where all sensors of the device are represented. As it is obvious from a screenshot below, the device «Mail Server» is configured to check the availability only using the command «Ping»:

List of configured sensors in the PRTG system device

To use a created notification «SMS Notification», there is a need to click the sensor «Ping» and go to the tab «Notifications»:

Applying notifications when the sensor triggers in PRTG

At the tab «Notifications» a response to the change in the status of sensors of a selected device is adjusted. To receive an SMS notification when a status of the sensor «Ping» is changed, there is a need to add a trigger by clicking the button «Add State Trigger» and fill in corresponding fields:

Setting up triggers for triggering SMS notifications in PRTG

where:
1 – is a condition, within which a notification will be triggered. In this example, a trigger will be activated when a sensor is in the status «Down»;
2 – is a period of time, within which a trigger will work. This period of time allows to avoid false triggering;
3 – is a method for sending notifications when a trigger will work;
4 – is a method for sending notifications, when a condition is not fulfilled anymore;
5 – saving parameters of a trigger

Configuring Devices NetPing SMS, UniPing server solution v4/SMS and NetPing 8/PWR-220 v4/SMS

To send SMS notifications as in the example (i.e. using the devices NetPing SMSUniPing server solution v4/SMSNetPing 8/PWR-220 v4/SMS  as an SMS gateway) there is a need to perform only a part of a basic configuration (configure network parameters to access the network) of the devices NetPing SMSUniPing server solution v4/SMS and NetPing 8/PWR-220 v4/SMS and insert a working SIM card with a positive balance into the slot of a built-in modem. You are welcome to read more about basic and additional configuration of devices in the documentation represented below:

Example of the PowerShell Script for Sending Random SMS Notifications about Events in the Monitoring System PRTG Network Monitor

Below you can see a code of a script on PowerShell. It needs to be copied into a text file and saved with the extension «.ps1» via the next path: "C:\Program Files (x86)\PRTG Network Monitor\Notifications\EXE".

$url = "http://192.168.0.100/sendsms.cgi"
$username = "visor"
$password = "ping"

foreach ($arg in $args)
{
Write-Host "Arg: $arg";
}

$req = [System.Net.WebRequest]::Create($url)
$req.Method = "POST";

$req.Credentials = new-object System.Net.NetworkCredential($username, $password)

$Body = [System.Text.Encoding]::UTF8.GetBytes($arg);

$stream = $req.GetRequestStream();
$stream.Write($Body, 0, $Body.Length);

$stream.Flush();
$stream.Close();

$resp = $req.GetResponse().GetResponseStream()
$resp.Close() 

where:

$url – is a variable, which sets an IP address of a NetPing device and a script to send random SMS messages.
$username – is a variable, which sets a username to get authorized for the device NetPing.
$password – is a variable which sets a password to get authorized for the device NetPing.

On default, performing PowerShell scenarios in the system is prohibited because scripts may contain a malicious code, which is able to damage a system. It is possible to disable verification of compliance scripts. To do this, there is a need to run a PowerShell console from a name of a system administrator and enter a command:

Set-ExecutionPolicy Unrestricted

Kindly read more detailed information about a script execution policy in a PowerShell environment in the article «Using the Set-ExecutionPolicy Cmdlet».

Result

As a result of configuring sending SMS notifications about events in the monitoring system PRTG Network Monitor while using SMS gateway on the basis of the devices NetPing SMSUniPing server solution v4/SMS or NetPing 8/PWR-220 v4/SMS described above, a staff will receive SMS notifications similar to the one below:

NetPing device - SMS notifications from PRTG


comments powered by Disqus