Restart windows processes?

Andy Stein andy at atcomputerconsulting.com
Wed Sep 3 16:05:46 CEST 2003


Sure -

But please be forewarned, I'm not a very modular coder.  My efforts
usually go to the task at hand and not always to the best reusability.

Also, I beat my head against the wall for a while trying to figure out
where to put the script so that when nagios authenticated to the windows
box it would be part of the path so I resolved that by putting the path in
the script.

Anyway, here's a script that the netsaint service on windows.  I used the
sample code that the nagios docs provide and just modified a few things.

This code goes on the windows box.  I have a path identified in the script
on the nagios side.

<windows code>
net stop nsclient
sleep 5
net start nsclient
</windows code>

And this is on the nagios side.  I have nagios authorized to login to the
windows box as me (i'm a domain admin), and in my opinion since I'm using
the keys this is pretty secure since only nagios is allowed to log in.
<nagios code>
#!/bin/sh
#
# Event handler script for restarting the nsclient service on the remote
machine
#
# Note: This script will only restart the web server if the service is
# retried 3 times (in a "soft" state) or if the web service somehow
# manages to fall into a "hard" error state.
#
# What state is the HTTP service in?
# ARG1=SERVICESTATE
# ARG2=STATETYPE
# ARG3=SERVICEATTEMPT
# ARG4=HOSTNAME
# SERVICE ALERT: usmnlm03;NS Client Version;CRITICAL;SOFT;2;Connection
refused by host

script_path=/cygdrive/c/docume~1/astein/nagios_scripts
cmd="ssh -l astein usmnla45 $script_path/nsclient.cmd $4"

case "$1" in
OK)
# The service just came back up, so don't do anything...
;;
WARNING)
# We don't really care about warning states, since the service is probably
still running...
;;
UNKNOWN)
# We don't know what might be causing an unknown error, so don't do
anything...
;;
CRITICAL)
        # Aha! The HTTP service appears to have a problem - perhaps we
should restart the server...
        # Is this a "soft" or a "hard" state?
        case "$2" in
        # We're in a "soft" state, meaning that Nagios is in the middle of
retrying the
        # check before it turns into a "hard" state and contacts get
notified... i
        SOFT)
                # What check attempt are we on? We don't want to restart
the web server on the first
                # check, because it may just be a fluke!
                case "$3" in
                        # If the check fails on the 2th time (after we
restart the service), the state
                        # type will turn to "hard" and contacts will be
notified of the problem.
                        # Hopefully this will restart the service
successfully, so the 2th check will
                        # result in a "soft" recovery. If that happens no
one gets notified because we
                        # fixed the problem!
                        2)
                                # Call the init script to restart the service
                                /usr/bin/printf "%b" "***** My  NOC
*****\n\n$cmd" | /bin/mail -s "ssh
notification " andy_stein at mysmtpmailserver
                                $cmd
                        ;;
                esac
        ;;
        # It should have been restarted by the code above, but for some
reason it didn't.

        # Let's give it one last try, shall we?
        # Note: Contacts have already been notified of a problem with the
service at this
        # point (unless you disabled notifications for this service)
        HARD)
                /usr/bin/printf "%b" "***** Brown & Williamson NOC
*****\n\n$cmd" | /bin/mail -s "ssh notification "
andy_stein at usnotessmtp
                $cmd
        ;;
        esac
;;
esac
exit 0
</nagios code>

> Andy,
>     Can you post a sample script ?
> thanks
> G
> "Andy Stein" <andy at atcomputerconsulting.com> wrote in message
> news:1973.192.168.1.5.1056826030.squirrel at www.atcomputerconsulting.com...
>> I'd been looking for this for a while, and here is what I came up with
>> and
>> it works pretty darn good.
>>
>> Get openSSH installed on your windows box.
>> http://lexa.mckenna.edu/sshwindows/ is a site that has a very simple
>> install.  Hurry up, site might be moving shortly.
>>
>> Get it configured so the Nagios process can use public key
>> authentication
>> on the box with the service to restart.  And when it fails, have an
>> event
>> handler bounce the service.
>>
>> One problem that I ran into was running scripts from the ssh command
>> originating from my linux box.  I had pathing problems.  When I would do
>> something like: "ssh windowserver -l myid restartservice.cmd" it
>> couldn't
>> find it.  So my solution was to just put the script in the system32
>> folder.  I do this with each script for a restart that I need to
>> perform.
>> I also had problems with \ and a few other issues.  So I basically do
>> everything within the script and only pass a small set of parameters
>> like
>> host name with no \ in it.
>>
>> Hope this helps.
>>
>> > you could use Samba-TNG, to build a plugin that will restart a windows
>> > service/process.
>> >
>> > Lane
>> >
>> > -----Original Message-----
>> > From: Olivier Beauchemin
>> > To: nagios-users at lists.sourceforge.net
>> > Sent: 6/27/2003 5:15 PM
>> > Subject: [Nagios-users] Restart windows processes?
>> >
>> >
>> > ...I was hoping someone here will know of a Nagios plug-in that will
>> > check and restart *Windows* processes?
>> >
>> > I've not been able to find anything that will do this, but I might
>> just
>> > have overlooked some nuance of some plug-in somewhere.
>> >
>> > Thanks,
>> > Olivier
>> >
>> >
>> >
>> > -------------------------------------------------------
>> > This SF.Net email sponsored by: Free pre-built ASP.NET sites including
>> > Data Reports, E-commerce, Portals, and Forums are available now.
>> > Download today and enter to win an XBOX or Visual Studio .NET.
>> > http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01
>> > _______________________________________________
>> > Nagios-users mailing list
>> > Nagios-users at lists.sourceforge.net
>> > https://lists.sourceforge.net/lists/listinfo/nagios-users
>> > ::: Please include Nagios version, plugin version (-v) and OS when
>> > reporting any issue.
>> > ::: Messages without supporting info will risk being sent to /dev/null
>> >
>> >
>> >
>> >
>>
>>
>>
>> -------------------------------------------------------
>> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
>> Data Reports, E-commerce, Portals, and Forums are available now.
>> Download today and enter to win an XBOX or Visual Studio .NET.
>> http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01
>> _______________________________________________
>> Nagios-users mailing list
>> Nagios-users at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/nagios-users
>> ::: Please include Nagios version, plugin version (-v) and OS when
> reporting any issue.
>> ::: Messages without supporting info will risk being sent to /dev/null
>>
>
>
>
>
>



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list