SpiceCorps of San Diego presentation on Alerts

11
Custom Notifications Spiceworks Alerts Michael Crook Senior Programmer Analyst

description

 

Transcript of SpiceCorps of San Diego presentation on Alerts

Custom Notifications

Spiceworks AlertsMichael Crook

Senior Programmer Analyst

Download me @ http://ucsdhc-hi.ucsd.edu/spiceworks.pptx

Enable Custom Notifications in Spiceworks

• From Settings open External Alerts• Enable external alert processing

• Send your Spiceworks a notification e-Mail

Displaying your new alert

Different methods used for notifications triggers

• Count files in a queue directory• Perform a command on a Unix server• Perform a Oracle DB query

What makes this all work

• VBScript to send the email • In this example, Inventory device UCSDIFOUT is posting an alert

“ORU_PCIS_ORM_WEBCHARTS > 25”

***** Nagios *****Host: UCSDIFOUTAddress: 172.16.82.89State: ORU_PCIS_ORM_WEBCHARTSService: ORU_PCIS_ORM_WEBCHARTS > 25Info: 30 ORU_PCIS_ORM_WEBCHARTS

Event_sender.vbs 30 ORU_PCIS_ORM_WEBCHARTS 25 UCSDIFOUT---------------------------------------------------------------------If Wscript.Arguments.Count = 0 Then

Else

dim dmsg

dim cnt

dim passed_msg

dim watermark

cnt = int(Wscript.Arguments(0) )

passed_msg = Wscript.Arguments(1)

watermark = int(Wscript.Arguments(2))

server= Wscript.Arguments(3)

Set o = CreateObject("CDO.Message")

o.From = "Imaging Services Support <[email protected]>"

o.To = "[email protected]"

o.Subject = "Alert"&passed_msg

if (cnt>watermark) then

dmsg = " "&cnt&" "&passed_msg

o.TextBody = "***** Nagios *****"&chr(13)&chr(10)& _

"Host: "&server&chr(13)&chr(10)& _

"Address: 172.16.000.000"&chr(13)&chr(10)& _

"State: "&passed_msg&chr(13)&chr(10)& _

"Service: "&passed_msg&" > "&watermark&chr(13)&chr(10)& _

"Info: "&dmsg&

else

o.TextBody = "***** Nagios *****"&chr(13)&chr(10)& _

"Host: "&server&chr(13)&chr(10)& _

"Address: 172.16.000.000"&chr(13)&chr(10)& _

"State: "&passed_msg&chr(13)&chr(10)& _

"Service: "&passed_msg&" > "&watermark&chr(13)&chr(10)& _

"Info: Cleared"

End If

o.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = “smtp.ucsd.edu"

o.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

o.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

o.Configuration.Fields.Update

o.Fields.Update

o.send

Set o = Nothing

End If

---------------------------------------------------------------------

Run a command on a UNIX box and parse the result

• Checking the CPU temp (prtdiag –v)• Run the command and return a filtered set of results

plink.exe -pw pass -batch user@server prtdiag -v |find "CPU%1 “

Use SQL commands to generate a Alert

• Create a text file containing the commands to send to SQLPlus i.e.select count(*) from pending_transactions;exit;

• To run the command and return a filtered result(Make sure your query only returns a single result)

sqlplus user/pass@ODB @SQLfile.SQL |find " ">SQLfile.txt

• Code example on next slide

Perform a Oracle DB Query and act on the result

sqlplus %OracleUser%/%OraclePass%@%oracle_sid% @%QliktechHome%\%SQLfile%.SQL |find " ">%QliktechHome%\%SQLfile%.txt

FOR /F "tokens=1" %%G IN ('type %QliktechHome%\%SQLfile%.txt') DO SET _tempVar=%%G

if %_tempVar% gtr %_watermark% (

%QliktechHome%\Event_sender.vbs %_tempVar% %_check_name% %_watermark% %_server%

echo _ %_tempVar% >%_check_name%-%_watermark%-%_server%

date /t >>log.txt

time /t >>log.txt

echo %QliktechHome%\Event_sender.vbs %_tempVar% %_check_name% %_watermark% %_server% >>log.txt

)

if %_tempVar% lss %_watermark% (

if exist %_check_name%-%_watermark%-%_server% (

%QliktechHome%\Event_sender.vbs %_tempVar% %_check_name% %_watermark% %_server%

del /Q %_check_name%-%_watermark%-%_server%

)

)