What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Is there a way to write custom ssh-sensors?

Votes:

0

Besides Linux, we need to monitor Solaris and Aix machines, too, but the standard Linux sensors often do not work for those Oss. So the Question is: Is there a way to write custom ssh-sensors and is there somewhere an example how to do this and/or how to use them?

custom custom-script-exe solaris ssh

Created on Nov 7, 2011 10:12:26 AM

Last change on Mar 20, 2015 2:19:41 PM by  Martina Wittmann [Paessler Support]



Best Answer

Accepted Answer

Votes:

0

Fortunately I can proof you're not right, I just did ;-).

Motivated ;-) by your reply, I did a little powershell scripting with PuTTY and found a solution that works. At this point it monitors ufs file systems on Solaris (free, %free, inodes, %inodes used), automatically discovering all available and mounted ufs file systems. As far as I can see, it basically works on Solaris 7/8/9 and 10 (more or less—but the script can easily be adjusted by somebody with some scripting knowledge). In my opinion this should work on AIX and other Unixes too, but I have not checked this yet. Because of using PuTTY (plink) as an ssh provider, it is not very important, but it should work in most cases as long as you don't use it in 60 sec intervals.

What you need:

On the Probeside:

  • PuTTY 0.56_or lower_ (due to a bug beginning in 0.58_or newer_, not fixed until 0.61)
  • Powershell 2.0
  • Some Free Space ;-)

On the other side (the unix-machine):

  • df, sed, awk, wc and, of course, an ssh-daemon
  • a non privileged user for login will do

A word on the ssh connection

Because it is a non interactive login, you have three options how to deal with that:

  • Exchange keys manually, with the advantage: no passwords are needed
  • If PRTG runs as a system account: have a look in the script's comments
  • Or you can run PRTG under a service account. In this case login as this service user and initiate an ssh connection with PuTTY once, so that the key can be stored in the service user's registry hive.

Note: It works (at least for me), but it is a really dirty scripting hack. If I'll have some time left, I'll replace PuTTY (plink) by some powershell-ssh-lib-comands which will have the advantage, that we can deal with objects, reducing overhead and making xml formatting easier.

What the script does:

The script takes some parameters from PRTG, determines how much ufs file systems there are, processes the fs-data and stores the date in an array. After gathering the data it makes an xml-style output with the data, using the api-specified layout and returns 4 channels per file system... pretty simple, isn't it?

How to use the script:

Put this script into the customsensor/exexml directory, name it "some_name_you_like.ps1". In PRTG, select customsensor/extended, name it somehow, chose the name you have given to the script as script, and fill the parameter field with: %device % linuxuser %linuxpassword, finish it and wait a while, depending on the amount of file systems your Solarisbox contains (six ufs.fs will take aproximately 30-40 sec).

The Script

# Test and Demo SSH Custom Sensor for PRTG
# Just a dirty hack and workaround using Powershell
# Requires: 
# + Putty and "plink" on the local Probe
# !!!! USE putty v 0.56 only !!! greater PuTTY Version 
# have a bug in plink.exe (unable to read from standard input)
# + PowerShell v. 2.0 on the local Probe
# + df, sed, awk on the other side (the unix machine)
#
# Required Parameters:
# + %device %linuxuser %linuxpassword (take care on the sequence)
#
# Please consider that this script is not very performant, so better raise
# the timeout parameters when using this sensor!
#
# Please note: PRTG is running as "Local System" on your probe machine. 
# unfortunately putty and so plink will store the key for your devices
# in the registry under your local account. So to make this script work,
# use putty and connect once to your devices you intend to monitor and confirm
# the key question. Now putty has written its key for your device into the registry
# You can find it under: HKEY_CURRENT_USER/Software/SimonTatham...and below. Export the complete
# SimonTatham tree and edit the exported reg-file: replace your SID, which may look like:
# S-1-5-21-3207534919-1055941624-1571275120-500 with the SID for the LocalSystem Account which is
# S-1-5-18. Save the edited reg-file and import it unter HKEY_USERS/S-1-5-18/Software, so that the keys
# are now available for the user PRTG is running on.
#
# Written and Copyright by: Andreas Hümmer <[email protected]> 
# Elaxy BSS GmbH & Co KG 
#
# Version
#  07.11.2011   V 0.1  initial release
#

$DEVICE=$args[0]
$USER=$args[1]
$PWD=$args[2]

#echo "--"
#echo "$DEVICE"
#echo "$USER"
#echo "$PWD"
#echo "--"


"<prtg>"


$COMMAND1="df -F ufs|wc -l"

$COUNT = & 'c:\Program Files (x86)\PuTTY\plink' $USER@$DEVICE -ssh -pw $PWD $COMMAND1

$NUM =  [System.Convert]::ToDecimal($COUNT)
If ($NUM -eq 0)
    {
        "no UFS Filesystem found or 'df' not available"
    }
else
    {
        $FILESYSTEM=@{}
        $FILESYSTEM = "FS-Number","Free Bytes","Free Space","Mountpoint","freeInodes","usedInodes"
        $FILESYSTEMS=@{}
        $FILESYSTEMS[0] = $FILESYSTEM
        For ($a=2; $a -le ($NUM+1); $a++)
            {
                $COMMAND2="df -k -F ufs | sed -n $a\p | awk '{ print `$4, `$5, `$6 }'"
                $COMMAND3="df -o i -F ufs | sed -n $a\p | awk '{ print `$3, `$4 }'"
                
                $FSKILOBYTES = & 'c:\Program Files (x86)\PuTTY\plink' $USER@$DEVICE -ssh -pw $PWD $COMMAND2
                $FSINODES = & 'c:\Program Files (x86)\PuTTY\plink' $USER@$DEVICE -ssh -pw $PWD $COMMAND3
                
                $DATAKB= @{}
                $DATAKB = $FSKILOBYTES.Split()
                $DATAINODE = @{}
                $DATAINODE = $FSINODES.Split()
                
                $DATA=@{}
                $DATA = ($a-1),$DATAKB[0],$DATAKB[1],$DATAKB[2],$DATAINODE[0],$DATAINODE[1]
                $FILESYSTEMS[($a-1)]=$DATA 
                
            }
 
            write-debug $FILESYSTEMS             
            
           # "<prtg>"
                For ($a=2; $a -le ($NUM+1); $a++)    
                    {
                        "<result>"
                            $CHANNELNAME = $FILESYSTEMS[0][1]+" "+$FILESYSTEMS[$a-1][3]
                            "<channel>"
                                "$CHANNELNAME"
                            "</channel>"
                            $VALUE=[System.Convert]::ToDecimal($FILESYSTEMS[$a-1][1])*1024
                            "<value>"
                                "$VALUE"
                            "</value>"
                            "<Unit>BytesDisk</Unit>"
                            "</result>"
                        "<result>"
                            $CHANNELNAME = $FILESYSTEMS[0][2]+" "+$FILESYSTEMS[$a-1][3]
                            "<channel>"
                                "$CHANNELNAME"
                            "</channel>"
                            $RAWVALUE=$FILESYSTEMS[$a-1][2].Replace("%","")
                            $VALUE=[System.Convert]::ToDecimal($RAWVALUE)
                            "<value>"
                                "$VALUE"
                            "</value>"
                            "<Unit>Percent</Unit>"
                        "</result>"
            
                        "<result>"
                            $CHANNELNAME = $FILESYSTEMS[0][4]+" "+$FILESYSTEMS[$a-1][3]
                            "<channel>"
                                "$CHANNELNAME"
                            "</channel>"
                            $VALUE=[System.Convert]::ToDecimal($FILESYSTEMS[$a-1][4])
                            "<value>"
                                "$VALUE"
                            "</value>"
                            "<Unit>Count</Unit>"
                         "</result>"
            
                        "<result>"
                            $CHANNELNAME = $FILESYSTEMS[0][5]+" "+$FILESYSTEMS[$a-1][3]
                            "<channel>"
                                "$CHANNELNAME"
                            "</channel>"
                            $RAWVALUE=$FILESYSTEMS[$a-1][5].Replace("%","")
                            $VALUE=[System.Convert]::ToDecimal($RAWVALUE)
                            "<value>"
                                "$VALUE"
                            "</value>"
                            "<Unit>Percent</Unit>"
                        "</result>"
                    }
        "</prtg>"
    }


Have fun and if you have questions...feel free to ask ;-)

By the way: Is anyone interested in an ssh mem/CPU sensor for Solaris?

Created on Nov 8, 2011 7:03:31 PM

Last change on Mar 20, 2015 2:14:59 PM by  Martina Wittmann [Paessler Support]



4 Replies

Votes:

0

hallo, custom ssh sensors are not supported at the moment, sorry.

Created on Nov 7, 2011 11:00:04 AM by  Aurelio Lombardi [Paessler Support]



Accepted Answer

Votes:

0

Fortunately I can proof you're not right, I just did ;-).

Motivated ;-) by your reply, I did a little powershell scripting with PuTTY and found a solution that works. At this point it monitors ufs file systems on Solaris (free, %free, inodes, %inodes used), automatically discovering all available and mounted ufs file systems. As far as I can see, it basically works on Solaris 7/8/9 and 10 (more or less—but the script can easily be adjusted by somebody with some scripting knowledge). In my opinion this should work on AIX and other Unixes too, but I have not checked this yet. Because of using PuTTY (plink) as an ssh provider, it is not very important, but it should work in most cases as long as you don't use it in 60 sec intervals.

What you need:

On the Probeside:

  • PuTTY 0.56_or lower_ (due to a bug beginning in 0.58_or newer_, not fixed until 0.61)
  • Powershell 2.0
  • Some Free Space ;-)

On the other side (the unix-machine):

  • df, sed, awk, wc and, of course, an ssh-daemon
  • a non privileged user for login will do

A word on the ssh connection

Because it is a non interactive login, you have three options how to deal with that:

  • Exchange keys manually, with the advantage: no passwords are needed
  • If PRTG runs as a system account: have a look in the script's comments
  • Or you can run PRTG under a service account. In this case login as this service user and initiate an ssh connection with PuTTY once, so that the key can be stored in the service user's registry hive.

Note: It works (at least for me), but it is a really dirty scripting hack. If I'll have some time left, I'll replace PuTTY (plink) by some powershell-ssh-lib-comands which will have the advantage, that we can deal with objects, reducing overhead and making xml formatting easier.

What the script does:

The script takes some parameters from PRTG, determines how much ufs file systems there are, processes the fs-data and stores the date in an array. After gathering the data it makes an xml-style output with the data, using the api-specified layout and returns 4 channels per file system... pretty simple, isn't it?

How to use the script:

Put this script into the customsensor/exexml directory, name it "some_name_you_like.ps1". In PRTG, select customsensor/extended, name it somehow, chose the name you have given to the script as script, and fill the parameter field with: %device % linuxuser %linuxpassword, finish it and wait a while, depending on the amount of file systems your Solarisbox contains (six ufs.fs will take aproximately 30-40 sec).

The Script

# Test and Demo SSH Custom Sensor for PRTG
# Just a dirty hack and workaround using Powershell
# Requires: 
# + Putty and "plink" on the local Probe
# !!!! USE putty v 0.56 only !!! greater PuTTY Version 
# have a bug in plink.exe (unable to read from standard input)
# + PowerShell v. 2.0 on the local Probe
# + df, sed, awk on the other side (the unix machine)
#
# Required Parameters:
# + %device %linuxuser %linuxpassword (take care on the sequence)
#
# Please consider that this script is not very performant, so better raise
# the timeout parameters when using this sensor!
#
# Please note: PRTG is running as "Local System" on your probe machine. 
# unfortunately putty and so plink will store the key for your devices
# in the registry under your local account. So to make this script work,
# use putty and connect once to your devices you intend to monitor and confirm
# the key question. Now putty has written its key for your device into the registry
# You can find it under: HKEY_CURRENT_USER/Software/SimonTatham...and below. Export the complete
# SimonTatham tree and edit the exported reg-file: replace your SID, which may look like:
# S-1-5-21-3207534919-1055941624-1571275120-500 with the SID for the LocalSystem Account which is
# S-1-5-18. Save the edited reg-file and import it unter HKEY_USERS/S-1-5-18/Software, so that the keys
# are now available for the user PRTG is running on.
#
# Written and Copyright by: Andreas Hümmer <[email protected]> 
# Elaxy BSS GmbH & Co KG 
#
# Version
#  07.11.2011   V 0.1  initial release
#

$DEVICE=$args[0]
$USER=$args[1]
$PWD=$args[2]

#echo "--"
#echo "$DEVICE"
#echo "$USER"
#echo "$PWD"
#echo "--"


"<prtg>"


$COMMAND1="df -F ufs|wc -l"

$COUNT = & 'c:\Program Files (x86)\PuTTY\plink' $USER@$DEVICE -ssh -pw $PWD $COMMAND1

$NUM =  [System.Convert]::ToDecimal($COUNT)
If ($NUM -eq 0)
    {
        "no UFS Filesystem found or 'df' not available"
    }
else
    {
        $FILESYSTEM=@{}
        $FILESYSTEM = "FS-Number","Free Bytes","Free Space","Mountpoint","freeInodes","usedInodes"
        $FILESYSTEMS=@{}
        $FILESYSTEMS[0] = $FILESYSTEM
        For ($a=2; $a -le ($NUM+1); $a++)
            {
                $COMMAND2="df -k -F ufs | sed -n $a\p | awk '{ print `$4, `$5, `$6 }'"
                $COMMAND3="df -o i -F ufs | sed -n $a\p | awk '{ print `$3, `$4 }'"
                
                $FSKILOBYTES = & 'c:\Program Files (x86)\PuTTY\plink' $USER@$DEVICE -ssh -pw $PWD $COMMAND2
                $FSINODES = & 'c:\Program Files (x86)\PuTTY\plink' $USER@$DEVICE -ssh -pw $PWD $COMMAND3
                
                $DATAKB= @{}
                $DATAKB = $FSKILOBYTES.Split()
                $DATAINODE = @{}
                $DATAINODE = $FSINODES.Split()
                
                $DATA=@{}
                $DATA = ($a-1),$DATAKB[0],$DATAKB[1],$DATAKB[2],$DATAINODE[0],$DATAINODE[1]
                $FILESYSTEMS[($a-1)]=$DATA 
                
            }
 
            write-debug $FILESYSTEMS             
            
           # "<prtg>"
                For ($a=2; $a -le ($NUM+1); $a++)    
                    {
                        "<result>"
                            $CHANNELNAME = $FILESYSTEMS[0][1]+" "+$FILESYSTEMS[$a-1][3]
                            "<channel>"
                                "$CHANNELNAME"
                            "</channel>"
                            $VALUE=[System.Convert]::ToDecimal($FILESYSTEMS[$a-1][1])*1024
                            "<value>"
                                "$VALUE"
                            "</value>"
                            "<Unit>BytesDisk</Unit>"
                            "</result>"
                        "<result>"
                            $CHANNELNAME = $FILESYSTEMS[0][2]+" "+$FILESYSTEMS[$a-1][3]
                            "<channel>"
                                "$CHANNELNAME"
                            "</channel>"
                            $RAWVALUE=$FILESYSTEMS[$a-1][2].Replace("%","")
                            $VALUE=[System.Convert]::ToDecimal($RAWVALUE)
                            "<value>"
                                "$VALUE"
                            "</value>"
                            "<Unit>Percent</Unit>"
                        "</result>"
            
                        "<result>"
                            $CHANNELNAME = $FILESYSTEMS[0][4]+" "+$FILESYSTEMS[$a-1][3]
                            "<channel>"
                                "$CHANNELNAME"
                            "</channel>"
                            $VALUE=[System.Convert]::ToDecimal($FILESYSTEMS[$a-1][4])
                            "<value>"
                                "$VALUE"
                            "</value>"
                            "<Unit>Count</Unit>"
                         "</result>"
            
                        "<result>"
                            $CHANNELNAME = $FILESYSTEMS[0][5]+" "+$FILESYSTEMS[$a-1][3]
                            "<channel>"
                                "$CHANNELNAME"
                            "</channel>"
                            $RAWVALUE=$FILESYSTEMS[$a-1][5].Replace("%","")
                            $VALUE=[System.Convert]::ToDecimal($RAWVALUE)
                            "<value>"
                                "$VALUE"
                            "</value>"
                            "<Unit>Percent</Unit>"
                        "</result>"
                    }
        "</prtg>"
    }


Have fun and if you have questions...feel free to ask ;-)

By the way: Is anyone interested in an ssh mem/CPU sensor for Solaris?

Created on Nov 8, 2011 7:03:31 PM

Last change on Mar 20, 2015 2:14:59 PM by  Martina Wittmann [Paessler Support]



Votes:

0

my English isn't very well, sorry ;)

Костыли plink.exe от PuTTY (заработало только с версией 0.57, т.к. 0.58 и выше добавляет лишнее при выводе, типа "Using keyboard-interactive authentication")

Копируем plink.exe в C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXE\ и ..\EXEXML\

Дальше нужно один раз вручную выполнить подключение к каждому серверу, чтобы получить ключи в реестр. Например: plink.exe -ssh 192.168.0.2 -l vasya -pw paSsw0rd echo "Hello, sensor!" Дальше там спросит что-то, — нажать "y", чтобы подтвердить получение ключа.

Копируем, как умеем, ключи из HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys\ в HKEY_USERS\S-1-5-18\Software\SimonTatham\PuTTY\SshHostKeys\

Перезагружаем PRTG Core Server Service, чтобы он начал распознавать plink.exe в своих папках, как Custom Sensors -> EXE/Script и EXE/Script Advanced.

Дальше создаём кастом сенсор, выбираем plink.exe, ну и т.д...

Example 1 {{{EXE/Script: plink.exe Parameters: -batch -ssh %host -l %linuxuser -pw %linuxpassword /home/prtg/fs_capacity.pl

  1. ee /home/prtg/fs_capacity.pl
  2. !/usr/bin/perl

if(`df -h /`=/\s([\.\w]+)\%/){ print"<prtg><result><channel>Disk Capacity</channel><value>$1</value><unit>Percent</unit></result></prtg>"; }

__END__}}}

Example 2 EXE/Script: plink.exe Parameters: -batch -ssh %host -l %linuxuser -pw %linuxpassword echo "0:Ok"

Created on Apr 2, 2012 10:27:09 AM

Last change on Apr 2, 2012 4:24:34 PM by  Torsten Lindner [Paessler Support]



Votes:

0

As of PRTG v12, there are two SSH Script sensors available out of the box which can execute a script file located on the target (e.g., Unix/Linux/Solaris/Mac OS X) system:

Created on Jan 22, 2014 6:15:15 PM by  Gerald Schoch [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.