Submit a ticketCall us

Systems Monitoring for Dummies
Our new eBook will teach you the fundamentals and help you create monitors and alerts that are effective, meaningful, and actionable. Monitoring is more than a checkbox on your to-do list. This free eBook will give you practical advice to help you succeed in all aspects of monitoring – discovery, alerting, remediation, and troubleshooting. Don’t miss out on this indispensable resource for newbies, experienced IT pros, and everyone in between. Register Now.

Home > Success Center > Archive > 2017December07 - WIP Deletes > Alert Action - Run Linux Script With Putty

Alert Action - Run Linux Script With Putty

Updated

Overview

Chad Every created this article that shows how you can execute scripts against a linux server as an alert action. The scripts can be customized however you'd prefer them to function. This example will show how to do a simple service/daemon restart for Apache. There are some prerequisites that need to happen first beforehand. If you've already done those then skip down to the Orion Configuration part.

This article is base on Thwack Post https://thwack.solarwinds.com/docs/D...ification.send

 

Environment

  • NPM 12

Steps

  • Change the following Orion services to run as a service account. I just created one called 'orionservice' and then restarted those 3 services once that change was made. The service account needs to be a local admin to the Orion server.

 

  • Install putty on your Orion server. Make sure you download the Windows Installer version. Once installed, log into your Orion server with the service account that you created. Open putty and connect to the linux server in question. You have to manually accept the SSH key to the host since those accepted keys are stored on a per user basis (In this case, the service account). Putty does not allow a SSH key to be automatically accepted via the command line. You only have to do this once per linux server. There are other ssh utilities that do allow SSH keys to be accepted automagically via the CLI, but this article will focus on Putty.

 

 

 

  • Optional - Add the install location for Putty into your environment variables. This help when creating the alert action since it can call just putty.exe instead of using the full Windows path to it.

 

 

  • In the Alert Trigger Condition you'll add the action: Execute an External Program.

 

Here is the full line in the 'Network path to external program'. I'm using an Orion variable, ${N=SwisEntity;M=Application.Node.IP_Address}, which allows the action to be dynamic.

     putty.exe -l <username> -pw <password> -m C:\SolarWindsScripts\Linux\apache.sh ${N=SwisEntity;M=Application.Node.IP_Address}

 

          ***Security Note: Putty also allows you to specify a key file with -i instead of using a password which is more secure.***

 

  • You'll replace the <username> and <password> with the actual linux account that you use.
  • On your Orion server create a folder in a location that your service account has access too. I created mine at C:\SolarWindsScripts\Linux\. In that folder you can place your scripts, this example just has a basic sh script called apache.sh.

         Example of apache.sh file

         /etc/init.d/httpd restart

         exit 0

  • Save Changes to that action and test. You can also test this by running the full command in step 1 in command prompt or powershell. Just replace the Orion variable at the end of the actual IP of the linux server

     

    From here you can write scripts to accomplish just about anything and improve any automation rolls. This gives SAM the ability to 'self heal' an application before anyone has to be involved in troubleshooting.

     

     

 

 

 

Last modified

Tags

This page has no custom tags.

Classifications

(not set)