-1

hope someone can help me please

i am fairly new to the ruby language and currently have a ruby job running that tells me the info on services running on one of my windows 2008 servers.

i have written the code to display the output on a css widget however my boss has asked me to include email alerts on the event that a service fails.

i know how to check a service and if the state is not running then an email will be sent but if the service is off then an email will be sent each time the job checks.

i need one email to be sent upon the service failing and then leave it at that. i know i could use a loop to achieve this however i dont know how to fit this into my code.

here is my code below

monitors = 
   [{name: 'service display name', svc: 'service name', host: '192.168.2.1'},
    {name: 'service display name', svc: 'service name', host: '192.168.2.1'},
    {name: 'service display name', svc: 'service name', host: '192.168.2.1'},
    {name: 'service display name', svc: 'service name', host: '192.168.2.1'},
    {name: 'service display name', svc: 'service name', host: '192.168.2.1'},
    {name: 'service display name', svc: 'service name', host: '192.168.2.1'},
    {name: 'service display name', svc: 'service name', host: '192.168.2.1'}]

SCHEDULER.every '5s', :first_in => 0 do |job|
statuses = Array.new

monitors.each do |monitor|
status = Service.status(monitor[:svc], monitor[:host]).current_state

if status == "running" 
result = 1
else
result = 0
end

if result == 1
        arrow = "icon-ok-sign"
        color = "green"
    else
        arrow = "icon-warning-sign"
        color = "red"
    end
statuses.push({label: monitor[:name], value: result, arrow: arrow, color: color})

on result = 0 i could include the smtp function but it will just email each time the job runs which is every 5 seconds

thanks for you time

mark

1 Answers1

0

i have fixed this by creating a log file and writing to the file depending on the status of the service if service is running then ok is written to the file if it is failed the failed is written each time it does something it checks the file first