Is there a way to write custom ssh-sensors?

Votes:

0

Your Vote:

Up

Down

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

custom solaris ssh

Created on Nov 7, 2011 10:12:26 AM by  AndreasHuemmer (150) 2 1



Best Answer

Accepted Answer

Votes:

0

Your Vote:

Up

Down

Fortunately I can proof your not right, I just did ;-).

Motivated ;-) by your reply I did a little powershellskripting with putty and found a working solution. At this point it monitors ufs filesystems on solaris (free, %free, inodes, %inodes used), automaticly discovering all available and mounted ufs filessystemems. As far as I can see it basicly works on solaris 7,8,9 and 10 (more or less - but can easyly adjusted by one with some scripting knowledge). IMHO this should work on AIX and other Unixes too, but I have not checked this yet. Because of using PuTTY (plink) as ssh provider it is not very important but should work in mist cases as long as you dont use it in 60sec intervalls.

So what is needed:

On the Probeside: Putty 0.56 or _lower_ (due to a bug beginning in 0.58 or newer. not fixed til 0.61) Powershell 2.0 Some Free Space ;-)

On the other side (the unix-machine): df, sed, awk, wc and of course a ssh-deamon. a non priliedged user for login will do.

Oh, a word on ssh connect: because it is a non interactive logon, you have three options how to deal with that: - manually exchanging keys ... with the advantage: no passwords are needed - if prtg runs as system account: look in the scripts comment - or you can run prtg under a service account, in that case log in as that serviceuser and initiate an ssh conect with putty once, so that the key can be stored in the serviceuseres registry hive.

Well in the end: It works (at least for me), but 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-formating easier.

What it does: The script takes some params from prtg, determins how much ufs filesystems are there and the processes the fs-data and stores the date in an array. after gathering data it makes an xml-style output with the data, with the api-specifies layout and returns 4channels per filesystem ..pretty simple, isnt it?

To Use: put this script into the cusotomsensor/exexml directory, name it "somewhat you like.ps1". In prtg, select customsensor/extended, name it somhow, 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 filesystems your solarisbox has. (six ufs.fs will take aproxxim. 30-40 sec).

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

Oh btw. is anyone intrested in a ssh mem/cpu sensor for solaris?

And here it is:

unfortunately the formating of this blog is, well let say not really, compatible with powershell syntax...if someone knows where to put the scriptfile for download/distribution, let me know ;-) --------------------------------- ---------------------------------

# 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 unixmachine)
#
# Required Parameters:
# + %device %linuxuser %linuxpassword (take care on the sequence)
#
# Please consider that this script is not very perfomant, so better raise
# the timeoutparameters when using this sensor!
#
# Please note: PRTG is running as "Local System" on your probemachine. 
# unfortunately putty and so plink will store the key for your devices
# in the registry under your lokal 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 whitch 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 Cpoyright by: Andreas Hümmer <andreas.huemmer@elaxy.com> 
# 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>"
    }


-----------------

Created on Nov 8, 2011 7:03:31 PM by  AndreasHuemmer (150) 2 1

Last change on Nov 10, 2011 1:29:34 PM by  Patrick Hutter [Paessler Support] (6,074) 3 3



3 Replies

Votes:

0

Your Vote:

Up

Down

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] (7,239) 3 1



Accepted Answer

Votes:

0

Your Vote:

Up

Down

Fortunately I can proof your not right, I just did ;-).

Motivated ;-) by your reply I did a little powershellskripting with putty and found a working solution. At this point it monitors ufs filesystems on solaris (free, %free, inodes, %inodes used), automaticly discovering all available and mounted ufs filessystemems. As far as I can see it basicly works on solaris 7,8,9 and 10 (more or less - but can easyly adjusted by one with some scripting knowledge). IMHO this should work on AIX and other Unixes too, but I have not checked this yet. Because of using PuTTY (plink) as ssh provider it is not very important but should work in mist cases as long as you dont use it in 60sec intervalls.

So what is needed:

On the Probeside: Putty 0.56 or _lower_ (due to a bug beginning in 0.58 or newer. not fixed til 0.61) Powershell 2.0 Some Free Space ;-)

On the other side (the unix-machine): df, sed, awk, wc and of course a ssh-deamon. a non priliedged user for login will do.

Oh, a word on ssh connect: because it is a non interactive logon, you have three options how to deal with that: - manually exchanging keys ... with the advantage: no passwords are needed - if prtg runs as system account: look in the scripts comment - or you can run prtg under a service account, in that case log in as that serviceuser and initiate an ssh conect with putty once, so that the key can be stored in the serviceuseres registry hive.

Well in the end: It works (at least for me), but 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-formating easier.

What it does: The script takes some params from prtg, determins how much ufs filesystems are there and the processes the fs-data and stores the date in an array. after gathering data it makes an xml-style output with the data, with the api-specifies layout and returns 4channels per filesystem ..pretty simple, isnt it?

To Use: put this script into the cusotomsensor/exexml directory, name it "somewhat you like.ps1". In prtg, select customsensor/extended, name it somhow, 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 filesystems your solarisbox has. (six ufs.fs will take aproxxim. 30-40 sec).

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

Oh btw. is anyone intrested in a ssh mem/cpu sensor for solaris?

And here it is:

unfortunately the formating of this blog is, well let say not really, compatible with powershell syntax...if someone knows where to put the scriptfile for download/distribution, let me know ;-) --------------------------------- ---------------------------------

# 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 unixmachine)
#
# Required Parameters:
# + %device %linuxuser %linuxpassword (take care on the sequence)
#
# Please consider that this script is not very perfomant, so better raise
# the timeoutparameters when using this sensor!
#
# Please note: PRTG is running as "Local System" on your probemachine. 
# unfortunately putty and so plink will store the key for your devices
# in the registry under your lokal 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 whitch 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 Cpoyright by: Andreas Hümmer <andreas.huemmer@elaxy.com> 
# 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>"
    }


-----------------

Created on Nov 8, 2011 7:03:31 PM by  AndreasHuemmer (150) 2 1

Last change on Nov 10, 2011 1:29:34 PM by  Patrick Hutter [Paessler Support] (6,074) 3 3



Votes:

0

Your Vote:

Up

Down

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 by  peoplenodes (0) 1

Last change on Apr 2, 2012 4:24:34 PM by  Torsten Lindner [Paessler Support] (15,450) 3 1



Please log in or register to enter your reply.


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.

PRTG
Network Monitor
Intuitive to Use.
Easy to manage.

150.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Visit
www.paessler.com

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

Top Tags


View all Tags