External Logic for NetPing Devices Based on PowerShell

  • Published In: Tutorial
  • Created Date: 2015-06-22
  • Hits: 20

The most typical issue of monitoring server rooms is controlling climate and environment while a computer equipment works. Tracking temperature parameters and making a decision on results may be automated.

Let us consider an example of automation for controlling a climate in a server room based on Microsoft PowerShell script.

This solution for monitoring is based on the device UniPing server solution v4/SMS and allows to turn on/off an air conditioner or a fan depending on a temperature in a server room and outside. A management logic is based on the script of Microsoft PowerShell, which is executed in Windows environment on one of existing servers or on any external PC, connected to the Internet.

The script is executed according to a schedule with a frequency specified in a Windows Scheduler: it polls temperature sensors and send commands to turn on/off cooling/air conditioning appliances via an SNMP protocol. The next conditions are checked:

  • if a temperature outside a server room is +20 °C or below, and more than +27 °C inside a server room, a fan will be turned on by the socket NetPing AC/DIN, and an air conditioner will be turned off by the IR transmitter IRC-TR v2;
  • if a temperature outside a server room exceeds +20 °C, and +27 °C inside a server room, then an air conditioner will be turned on by the IR transmitter IRC-TR v2, and a fan will be turned off by the socket NetPing AC/DIN;
  • if a temperature inside a server room is +27 °C or below, all appliances will be turned off

The next equipment will be necessary to implement a represented solution:

In addition, Windows environment is necessary to execute a PowerShell script. It can be either a virtual machine on existing servers/a full OS or a PC connected to a local network/a remote PC on the Internet.

If NetPing equipment uses a router with NAT and/or Firewall feature to access the Internet, and a PowerShell script is going to be executed on a PC outside a local network, there is a need to enable incoming packages via an SNMP protocol (UDP/161) for a NetPing device to control it remotely. For an additional information see a documentation for a router or ask a network administrator.

If necessary, a NetPing device can be connected to a router using a wireless technology Wi-Fi by the adapter VAP11N. The adapter is purchased separately.

Let us configure a simplified scheme, when a Windows environment for execution a PowerShell script is located in the same local network with a NetPing device.

Configuring UniPing server solution v4/SMS

Get the device UniPing server solution v4/SMS into an operating condition according to corresponding sections in «User Guide».

Change the section Network Settings in the section SETUP of a device as follows:

  • IP Address: 192.168.0.21
  • Netmask: 255.255.255.0
  • Gateway: 192.168.0.1

All further settings of a device are configured according to the newly specified IP address. Please, see additional information in «Firmware description».

Network settings NetPing devices

In the section SETUP of a device change Username and Password to access a device. Change the fields Сommunity read/write to avoid unauthorized access to ping21.

Access Restrictions NetPing devices

Go to the section IR COMMANDS and record commands to control an air conditioner using a remote according to «Firmware description»:

  • save a command to turn on an air conditioner at the first row;
  • save a command to turn off an air conditioner at the second row

IR Commands NetPing devices 

Plug two temperature sensors to a device. In the section TEMPERATURE, identify a temperature sensor outside a server room as Sensor 3, and the one inside a server room as Sensor 5. Kindly see an additional information in «Firmware description».

TEMPERATURE NetPing devices

Go to the section DESCRETE IO and install Output operating mode for the socket NetPing AC/DIN.

DESCRETE IO NetPing AC DIN NetPing devices

Windows PowerShell Environment Configuration

There is a need to make sure that a used Windows environment supports implementing PowerShell scripts. For an additional information, go to the Microsoft's website. Install required packages or update to the latest versions if necessary.

Since Microsoft company has not provided a possibility to work with PowerShell via an SNMP protocol, there is a need to install NetCmdlets to support SNMP, which is a third-party module. A full version of this module is free for non-commercial use (there is a need to register to receive an activation key).

Then configure an automatic launch for a PowerShell script. A recommended launch schedule is 5 minutes. To configure it, use a previous article at the Microsoft website or a similar one from other sources.

Example of a PowerShell Script for Controlling a Climate in a Server Room

#UniPing server solution v4/SMS PowerShell Script

#Check if module NetCmdlets is installed
if(!(Get-Module | Where {$_.Name -eq "NetCmdlets"})) {
Import-Module "NetCmdlets"
}

# Setting variables
$community = "ping21"
$port = 16121
$hostip = "np.tst.netping.ru"
$Tout_cond = 20
$Tint_cond = 27
$Tout = (Get-SNMP -Agent $hostip -Port $port -Community $community -OID .1.3.6.1.4.1.25728.8800.1.1.2.3).OIDValue # датчик 3
$Tint = (Get-SNMP -Agent $hostip -Port $port -Community $community -OID .1.3.6.1.4.1.25728.8800.1.1.2.5).OIDValue # датчик 5

# 1) If a temperature outside is 20 or less, and a temperature inside is more than 27, then turn a fan on using the socket NetPing AC/DIN
if (($Tout -le $Tout_cond) -and ($Tint -gt $Tint_cond)) {
Write-Host "A fan will be turned on..."
# Checking if a socket for an IO 8 is switched on
if ((Get-SNMP -Agent $hostip -Port $port -Community $community -OID .1.3.6.1.4.1.25728.8900.1.1.3.8).OIDValue -ne 0 ) {
# Switching on a socket for a fan
Set-SNMP -Agent $hostip -Port $port -Community $community -OID .1.3.6.1.4.1.25728.8900.1.1.3.8 -OIDType Integer -OIDValue 0
Write-Host "...turning a fan on."
# Turning an air conditioner off via IR
Set-SNMP -Agent $hostip -Port $port -Community $community -OID .1.3.6.1.4.1.25728.7900.1.1.0 -OIDType Integer -OIDValue 2
}
else {Write-Host "...a fan is already turned on."}
}

# 2) If it is more than 20 outside, and more than 27 inside, then turn on an air conditioner using IRC-TR v2
elseif (($Tout -gt $Tout_cond) -and ($Tint -gt $Tint_cond)) {
Write-Host "Turning on an air conditioner..."
# Sending an IR command to turn on an air conditioner
Set-SNMP -Agent $hostip -Port $port -Community $community -OID .1.3.6.1.4.1.25728.7900.1.1.0 -OIDType Integer -OIDValue 1
# Turning off a socket for a fan
Set-SNMP -Agent $hostip -Port $port -Community $community -OID .1.3.6.1.4.1.25728.8900.1.1.3.8 -OIDType Integer -OIDValue 1
}

# 3) If it is 20 or less inside, then turn everything off (an air conditioner using IRC-TR v2 and a fan using the socket NetPing AC/DIN)
else {
Write-Host "Too cold - turning off all appliances."
# Turning off a socket for a fan
Set-SNMP -Agent $hostip -Port $port -Community $community -OID .1.3.6.1.4.1.25728.8900.1.1.3.8 -OIDType Integer -OIDValue 1
# Turning off an air conditioner via IR
Set-SNMP -Agent $hostip -Port $port -Community $community -OID .1.3.6.1.4.1.25728.7900.1.1.0 -OIDType Integer -OIDValue 2
}

where:

$community is a variable, which sets Community at the page «Setup» of a device web interface.

$port is a variable, which sets a port of an SNMP agent.

$hostip is a variable, which sets an IP address or a DNS name of a NetPing device.

$Tout_cond is a variable, which sets a threshold for a temperature outside a server room.

$Tint_cond is a variable, which sets a threshold for a temperature inside a server room.

$Tout is a variable, which shows a temperature value via an SNMP from a temperature sensor installed outside a server room.

$Tint is a variable, which shows a temperature value via an SNMP from a temperature sensor installed inside a server room.


comments powered by Disqus