Skip to content

Instantly share code, notes, and snippets.

@olibob
Created February 7, 2013 06:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olibob/4728975 to your computer and use it in GitHub Desktop.
Save olibob/4728975 to your computer and use it in GitHub Desktop.
GSA snmp monitoring script
#!/usr/bin/env ruby
# Author: Olivier Robert
# Email: olivier.robert@ext.europarl.europa.eu
# Date: 02/05/2013
# Version: 0.0.1
# Usage: gsaMon <snmp agent>
#
# Description:
# snmp query to a GSA appliance:
# => system.temperature.temperatureHealth Integer, Read-only Temperature status:
# => system.gsaDisk.diskHealth Integer, Read-only, Disk status:
# => system.machine.machineHealth Integer, Read-only Machine status:
# Possible status:
# 0 = Green (OK)
# 1 = Yellow (Warning)
# 2 = Red (Critical Warning)
#
# !!! Important !!!
# For this script to work you'll need to copy the google supplied MIBs to /usr/local/share/snmp/mibs/ on your solaris host
# https://developers.google.com/search-appliance/documentation/50/help_gsa/admin_snmp
require 'logger'
class GsaMon
# !!! class uses external snmp tools commands !!!
def initialize(snmpAgent)
@agent = snmpAgent
end
# Displays all the search appliance MIB contents
def showAvailableOIDs
return %x[snmpwalk -m +GSA-MIB -v 2c -c public -t 5 #{@agent} google]
end
# Search appliance status
def checkStatus
# checks status for machineHealth, diskHealth and temperatureHealth
# returns true or false
# Possible status
statusValues = {0 => "Green (OK)", 1 => "Yellow (Warning)", 2 => "Red (Critical Warning)"}
# status
@gsaStatus = {:machine => 0, :disk => 0, :temp => 0}
# oids checked
oids = {:machine => "GSA-MIB::machineHealth.0", :disk => "GSA-MIB::diskHealth.0", :temp => "GSA-MIB::temperatureHealth.0"}
result = true
oids.each do |k,v|
gsaStatusString = %x[snmpget -m +GSA-MIB -v 2c -c public -t 15 #{@agent} #{v}]
if $?.success?
# check for returned value in parenthesis
m = /\((\d)\)/.match(gsaStatusString)
if m
@gsaStatus[k] = statusValues[m[1].to_i]
result = false if m[1].to_i > 0
end
else
@gsaStatus[k] = "snmp query failed!"
result = false
end
end
return result
end #checkStatus
def getStatus
# should be called after checkStatus
statusString = ""
@gsaStatus.each do |k,v|
statusString += "#{k.to_s}: #{v.to_s} "
end
return statusString
end
end #class
if __FILE__ == $0
if !ARGV[0]
puts "Please supply a snmp agent: ./gsaMon snmp_agent_to_monitor"
exit 1
else
agent = ARGV[0]
end
ITOGROUP = "ITO-APPLI-EXPERT"
logPath = "/LOG/APPLI/gsa/#{agent}.log"
log = Logger.new(logPath, 'daily')
#log.level = Logger::DEBUG
log.level = Logger::INFO
log.debug "Initiating snmp query for agent #{agent}"
g = GsaMon.new(agent)
if !g.checkStatus
m = /snmp query failed/.match(g.getStatus)
if m
issue = "Could not communicate with snmp agent #{agent}: timeout or connection issue!"
log.error "#{issue}"
#%x[pecawto gsaMon.rb APPLI GSA gsaMon #{issue}]
exit 2
else
log.debug "oops, lost polarized plates ... virtual gravity lost ;-)"
log.error "#{agent} status: #{g.getStatus}"
log.error "Log on to http://#{agent}:8000/EnterpriseController from eici{L|B}UP03{1|2} (#{ITOGROUP})"
log.error "If necessary, open a case with Google https://google.secure.force.com/ (#{ITOGROUP})"
#%x[pecawto gsaMon.rb APPLI GSA gsaMon #{g.getStatus}]
log.error "NSM alert triggered."
exit 3
end
else
log.info "#{agent} status: #{g.getStatus}"
end
log.debug "Check done. Waiting for tectonics plates to shift ... Good bye!"
log.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment