Permalink
Browse files

Merge branch 'master' of github.com:ripienaar/mcollective-plugins

  • Loading branch information...
2 parents f34a2e9 + 59a8667 commit fa9f1e4f03c70909cfd1abf0de524b92e8dcef05 @ripienaar ripienaar committed Aug 18, 2010
Showing with 58 additions and 0 deletions.
  1. +58 −0 agent/registration-mongodb/check_mcollective.rb
@@ -0,0 +1,58 @@
+#!/usr/bin/env ruby
+#
+# Original one (file based) by R.I. Pienaar : http://www.devco.net
+# Mongo version by Nicolas Szalay : http://www.rottenbytes.info
+
+
+require 'getoptlong'
+require 'mongo'
+
+opts = GetoptLong.new(
+ [ '--interval', '-i', GetoptLong::REQUIRED_ARGUMENT],
+ [ '--host', '-h', GetoptLong::REQUIRED_ARGUMENT],
+ [ '--database', '-d', GetoptLong::REQUIRED_ARGUMENT],
+ [ '--collection', '-c', GetoptLong::REQUIRED_ARGUMENT]
+)
+
+total = 0
+old = 0
+interval = 300
+mongohost="localhost"
+mongodb="puppet"
+collection="nodes"
+
+opts.each do |opt, arg|
+ case opt
+ when '--interval'
+ interval = arg.to_i
+ when '--host'
+ mongohost = arg
+ when '--database'
+ mongodb = arg
+ when '--collection'
+ collection = arg
+ end
+end
+
+
+dbh=Mongo::Connection.new(mongohost).db(mongodb)
+coll=dbh.collection(collection)
+coll.find().each { |row|
+ seen = row["lastseen"]
+ fqdn = row["fqdn"]
+
+ total +=1
+
+ if (Time.now.to_i - seen) > interval
+ old+=1
+ end
+}
+
+if old > 0
+ puts("CRITICAL: #{old} / #{total} hosts not checked in within #{interval} seconds| totalhosts=#{total} oldhosts=#{old} currenthosts=#{total - old}")
+ exit 2
+else
+ puts("OK: #{total} / #{total} hosts checked in within #{interval} seconds| totalhosts=#{total} oldhosts=#{old} currenthosts=#{total - old}")
+ exit 0
+end
+

0 comments on commit fa9f1e4

Please sign in to comment.