It took me a while to get all the pieces together so I thought I'd share this quick guide on building a command line probe that connects from a Windows Intermapper server to a Linux server. The Probe code is loaded through the Import menu. Change some of the identifiers if needed. The method below is using plink to perform a command-line based SSH connection (plink is part of the PuTTY toolset).

  EXE below may executed as specfic system user. Make sure plink can be executed cleanly.

  type = "cmd-line"
  package = "packagename"
  probe_name = "Linux_Command"
  human_name = "Linux Command"
  version = "1.0"
  address_type = "IP"



  path = "C:\Intermapper\InterMapper Settings\Tools"
  cmd = "linux_check.bat"

  down: ${EXIT_CODE} = 2
  alarm: ${EXIT_CODE} = 1
  okay: ${EXIT_CODE} = 0


The batch file is located in the Intermapper Settings\Tools folder. This is the default location but defining it explicitly cannot hurt in this case. The command-exit part matches the exit status of the script with the alarm state. If the Linux script exits with code 0, the probe color is green, etc. PLink passes on the script exit status. The command-display part can show additional information. The $result value is mapped to the returned data. The batch file (linux_check.bat) below:

@echo off
rem echo %USERNAME% > C:\Temp\Test.txt
rem echo y | plink.exe -i C:\Temp\privkey.txt root@ /tmp/ 2>> C:\Temp\Test.txt
plink.exe -i C:\Temp\privkey.txt root@ /tmp/ 2>> C:\Temp\Test.txt

Copy plink.exe (from the PuTTY toolset) in the local folder (c:\Temp\ in this case). Generate a public and private key with PuTTYgen and export the public key in OpenSSH format. Copy the key to the authorized_keys file on the Linux server for the specific user you're connecting as (in this case, /root/.ssh/authorized_keys). Don't overwrite the file but append! This step is to ensure a key-less login for plink. Place the private key in a local folder (C:\Temp) in this case. The keyfile here is called privkey.txt. The first time, plink will attempt to add registry information for the remote key. For the very first run, change the batchfile to (remove rem for that line, add rem on the last one).

echo y | plink.exe -i C:\Temp\privkey.txt root@ /tmp/ 2>> C:\Temp\Test.txt

This will send a "y" to the request to add the key to the registry. For debugging on this line, use

plink.exe -i c:\Temp\privkey.txt root@ /tmp/ 2>> c:\Temp\debug.txt

This will send all error output (for instance, the plink request for adding the key to the registry, to debug.txt. In the batch file, plink will connect to as root (using the private key). The script on the Linux system contains:

echo "\{ \$result := 5 }"
exit 0

The exit code (0 in this case) is mapped to "okay", see above. Change this or map it to a dynamic value to change the probe status where needed. The echo line contains any additional information your probe will return. The $result variable is mapped above. This script uses a static value but a dynamic value can be used as well. This value is mapped to the command-display block above. Multiple values can be mapped if needed. See the probe guide.

In my case, the script is executed not as the current user but as a local user (system or otherwise). To discover the username, add the following line to the batch file:


echo %USERNAME% >> F:/Temp/debug.txt

Using the "echo Y |" trick described above will normally fix any issues you may have with the PuTTY key. If the paths to the plink executable don't work, move it around to a different location.


Submitted by hvanbelleghem on 7.8.14