Hi, i m searching how to add “perfdata” to my plugins.
With other plugins like “ping” i have this :
I want to add the same thing for my own check command but i didn’t find the .conf file.
I found a diretory with +1000 file named xxxxperfdata but they are genereated every 15 seconds.
Do you know how can i modify perfdata and then modify warning/critical level ?
thanks
can you share the code of your check plugin? Then we may give you hints on where to add the values. I assume you already have read the plugin API specification, right?
It works you right ! But i still doesn’t know where I have to define the “warning value” , i must define it in the ruby script ? or in an other .conf file ?
i’ve modified arguments, i had conflict with previous arguments, i have also modified IF structure and i had to convert string into numeric value for each if. Maybe some things or not really usefull but it work now.
#!/usr/bin/ruby
require 'net/imap'
require 'optparse'
require 'time'
#############
# Variables #
#############
opts = {
host: '',
user: '',
pass: '',
port: 993,
folder: 'INBOX',
usessl: false,
time: 3600
}
#############
# Arguments #
#############
OptionParser.new do |o|
o.banner = "Usage: #{$PROGRAM_NAME} -s <server> -u <user> -p <pass> [opts]"
o.on('-h', '--help', 'Prints this help.') { puts o && exit }
o.on('-sSERVER', '--server=SERVER', 'IMAP server.') { |s| opts[:server] = s }
o.on('-uUSER', '--user=USER', 'Login user.') { |u| opts[:user] = u }
o.on('-wPASS', '--password=PASS', 'Login password.') { |w| opts[:pass] = w }
o.on('-pPORT', '--port=PORT', 'IMAP server port.') { |p| opts[:port] = p }
o.on('-fFOLDER', '--folder=FOLDER', 'Mailbox.') { |f| opts[:folder] = f }
o.on('-l', '--use-ssl', 'Use SSL.') { opts[:usessl] = true }
o.on('-tPERIOD', '--time=PERIOD', 'Period.') { |t| opts[:time] = t.to_i }
o.on('-yWARN', '--warn=WARN', 'Warning count.') { |y| opts[:warn] = y }
o.on('-cCRIT', '--crit=CRIT', 'Critical count.') { |c| opts[:crit] = c }
end.parse!
########
# Main #
########
imap = Net::IMAP.new(opts[:server], opts[:port], opts[:usessl])
imap.login(opts[:user], opts[:pass])
imap.examine(opts[:folder])
arr = []
target = Net::IMAP.format_date(Time.now - opts[:time])
imap.search(['SINCE', target]).each do |id|
arr.push Time.parse(imap.fetch(id, 'ENVELOPE')[0].attr['ENVELOPE'].date).to_i
end
latest = arr.max
boxes = ["INBOX"] # list all the IMAP folders to include in the calculations
# loop through all boxes, adding all mail-ids to the list
mail_ids = boxes.inject([]) do |sum, box|
imap.select("INBOX")
sum += imap.search(["ALL"])
end
mail_count=mail_ids.count
warn = opts[:warn] # TODO: default values?
crit = opts[:crit]
output = "Vous avez un total de #{mail_count} mail(s) | 'count'=#{mail_count};#{warn};#{crit}"
if mail_count > crit.to_i
puts "CRITICAL - " + output
exit(2) # 2.. critical
elsif mail_count > warn.to_i
puts "WARNING - " + output
exit(1) # 1.. warning
else
puts "OK - " + output
exit(0) # 0.. ok
end
Cool, thanks. Just a tip for future postings - wrap code blocks with 3 back ticks before and after, for better highlighting. You can see that with my edits