views:

658

answers:

2

I have a problem with stopping a service and starting it again and want to be notified when the process runs and let me know what the result is.

Here's the scenario, I have a text file output of an "sc" command. I want to send that file but not as an attachment. Also, I want to see the initial status quickly in the subject of the email.

Here's the 'servstop.txt' file contents:

[SC] StartService FAILED 1058:

The service cannot be started, either because it is disabled or because it has no enabled devices associated with it.

I want the subject of the email to be "Alert Service Start: [SC] StartService FAILED 1058" and the body to contain the entire error message above.

I will put my current method in an answer below using a program called blat to send me the result.

+1  A: 

Here's how I'm doing this. First I got blat mail (public domain smtp mailer) and dropped it into d:\blat directory. My Exchange server allows me to email without id/password and just assumes that I am the person in the 'from' field of the blat command.

@echo off
sc start Alerter >servstop.txt
SetLocal EnableDelayedExpansion
set content=
set subj=
for /F "delims=" %%i in (servstop.txt) do set content=!content! %%i  
for /f "tokens=1 delims=:" %%s in ("%content%") do set subj=%%s 

d:\blat\blat.exe -body "%content%" -to [email protected] -f [email protected] -server smtp.foo.bar -s "Alert Service Start:%subj% " -log d:\blat\blat.log
EndLocal
Keng
+1  A: 

Splunk looks promising. Haven't tried it though. Two blockquotes from the site about index and alert below.

INDEX: With a variety of flexible input methods you can index logs, configurations, traps and alerts, messages, scripts, and code and performance data from all your applications, servers and network devices. Monitor file systems for scripts and configuration changes, capture archive files, find and tail live application logs, connect to network ports to receive syslog, SNMP and other network-based instrumentation. And this is just where it starts.

ALERT: Any search can be run on a schedule and trigger notifications or actions based on the search results. And because it works across different components and technologies, Splunk is the most flexible monitoring tool in your arsenal. Notifications can be sent via email, RSS or SNMP to other management consoles. Actions trigger scripts performing user described activities like restarting an application, server or network device.

Mackaaij
splunk is awesome! my network buddy loves it and here's a great vid on someone doing splunk over Amazon's EC2http://blogs.splunk.com/thewilde/2008/06/17/splunk-ninja-cloud-power-splunkin-with-amazons-ec2/
Keng