TECHZEN Zenoss User Community ARCHIVE  

Run script/command on event

Subject: Run script/command on event
Author: R S
Posted: 2015-03-05 12:29

Can someone point me in the right direction I'd like to be able to shutdown a group of windows servers when an event from a water sensor is triggered,. It is currently monitored and the status change triggers an email. However, I'm hoping to for something like....

Water is detected by sensor
sends trap to Zenoss
Email triggered
------------------------
everything above is currently working
______________
after email is triggered
delay 30 seconds
send command to shutdown 4 severs

I did find http://www.ohjeah.net/2009/03/03/remoe-server-shutdown/ but when my threshold is activated where and how do I enter in this "script"



Subject: I suspect you're en-route
Author: Andrew Kirch
Posted: 2015-03-05 14:12

I suspect you're en-route down a rabbit hole here... You have a shutdown windows from windows, and a shutdown linux from linux script. I'm not even certain I'm going to suggest the correct direction, but I'd look to see if you can build a BASH script that invokes an Active Directory command via SAMBA (samba.org) to shut down a server using ${dev/ManageIp} as the first ARGV of the script.

Once you have a working script you can use a Command Notification to invoke it.

Andrew Kirch

akirch@gvit.com

Need Zenoss support, consulting or custom development Look no further. Email or PM me!

Ready for Distributed Topology (collectors) for Zenoss 5 Coming May 1st from GoVanguard



Subject: I may actually be headed in
Author: Andrew Kirch
Posted: 2015-03-05 14:22

I may actually be headed in the right direction. Further research has lead me to samba's 'net' command. Which is in your example. This means you will have to have Samba installed and joined to AD.
from # man net
RPC SHUTDOWN [-t timeout] [-r] [-f] [-C message]
Shut down the remote server.

-r
Reboot after shutdown.

-f
Force shutting down all applications.

-t timeout
Timeout before system will be shut down. An interactive user of the system can use this time to cancel the shutdown.

-C message
Display the specified message on the screen to announce the shutdown.

so adding a Command Notification containing something along the lines of:
net rpc shutdown -C "WATER SHUTDOWN" -f -S ${dev/ManageIp} -U ${dev/zWinRMUser}%${dev/zWinRMPassword} assuming that the WinRM user used to monitor has rights to shut down.

Note that I am not a Windows Admin and I expressly disclaim any responsibility if this causes windows to fail in some way other than in which windows normally fails.

Andrew Kirch

akirch@gvit.com

Need Zenoss support, consulting or custom development Look no further. Email or PM me!

Ready for Distributed Topology (collectors) for Zenoss 5 Coming May 1st from GoVanguard



Subject: While I'd like to do a few
Author: R S
Posted: 2015-03-05 16:07

While I'd like to do a few more real world tests, I've got one working. No need to actually join the AD, just have the samba tools installed. I will add additional lines of the same command for each IP address.

net rpc SHUTDOWN -C "Automated shutdown" -f -I "IPADDRESS HERE" -W DOMAINNAME -U username%password

Now to figure out scripting a linux shutdown (qnap box)



Subject: ssh -c user@host shutdown -h
Author: Andrew Kirch
Posted: 2015-03-06 07:16

ssh -c user@host shutdown -h now

Andrew Kirch

akirch@gvit.com

Need Zenoss support, consulting or custom development Look no further. Email or PM me!

Ready for Distributed Topology (collectors) for Zenoss 5 Coming May 1st from GoVanguard



Subject: The command is actually a
Author: R S
Posted: 2015-03-06 09:56

The command is actually a little different for a qnap
http://www.openremote.org/display/docs/Remote+Control+QNAP+Start,+Shutdo...

I'm just confused on this script and can't get it to work. The actual script is supposed to read

#!/bin/bash
username="$1"
hostname="$2"
password="$3"
sshpass -p "$password" ssh "$username"@"$hostname" /sbin/poweroff

and then I call the script ./qnapshutdown.sh username IPAddress SSH-password



Subject: I needed to ssh into the qnap
Author: R S
Posted: 2015-03-06 12:44

I needed to ssh into the qnap so zenoss could add the device to its list of known ssh machines. After that I could get it to shutdown



Subject: If you generally trust your
Author: [Not Specified]
Posted: 2015-03-06 14:06

If you generally trust your environment and don't want to have to ssh in advance to every possible server, check out the -o StrictHostKeyChecking=no option



Subject: I used the ssh-keygen util to
Author: R S
Posted: 2015-03-06 16:04

I used the ssh-keygen util to make the process easier, and it was only the one linux box (raspberry pi runs my WOL cron, and I don't want it waking up my servers in the event of a flood in my server room lol)



< Previous
Improve the Filesystem usage graphs
  Next
monitor by hostname instead of ip address?
>