old_contents: #!/usr/bin/env /usr/bin/python
  import check_rabbit_queue
  import urllib2
  import json
  from pynagios import Plugin, make_option, Response, WARNING, CRITICAL
  from urllib2 import Request, urlopen, URLError, HTTPError
  
  from base_rabbit_check import BaseRabbitCheck
  
  
  class RabbitQueueCheck(BaseRabbitCheck):
  	"""
  	performs a nagios compliant check on a single queue and
  	attempts to catch all errors. expected usage is with a critical threshold of 0
  	"""
  
  	vhost = make_option("--vhost", dest="vhost", help="RabbitMQ vhost", type="string", default='%2F')
  	queue = make_option("--queue", dest="queue", help="Name of the queue in inspect", type="string")
  
  
  	def makeUrl(self):
  		"""
  		forms self.url, a correct url to polling a rabbit queue
  		"""
  		try:
  			self.url = "http://%s:%s/api/queues/%s/%s" % (self.options.hostname, self.options.port, self.options.vhost, self.options.queue)
  			return True
  		except Exception, e:
  			self.rabbit_error = 3
  			self.rabbit_note = "problem forming api url:", e
  		return False
  
  	def testOptions(self):
  		"""
  		returns false if necessary options aren't present
  		"""
  		if not self.options.hostname or not self.options.port or not self.options.vhost or not self.options.queue:
  			return False
  		return True
  
  	def setPerformanceData(self, data, result):
  		result.set_perf_data(self.queue + "_messages", data['messages'])
  		result.set_perf_data(self.queue + "_rate", data['messages_details']['rate'])
  		result.set_perf_data(self.queue + "_consumers", data['consumers'])
  		result.set_perf_data("rabbit_error", self.rabbit_error)
  		return result
  
  	def parseResult(self, data):
  		self.queue = self.options.queue
  		result = self.response_for_value(data['messages'])
  		result.message = ' found ' + str(data['messages']) + ' messages'
  		self.rabbit_note = ' found ' + str(data['messages']) + ' messages'
  		return result
  
  
  if __name__ == "__main__":
  	obj = RabbitQueueCheck()
  	obj.check().exit()
  
new_contents: #!/usr/bin/env /usr/bin/python
  import check_rabbit_queue
  import urllib2
  import json
  from pynagios import Plugin, make_option, Response, WARNING, CRITICAL
  from urllib2 import Request, urlopen, URLError, HTTPError
  
  from base_rabbit_check import BaseRabbitCheck
  
  
  class RabbitQueueCheck(BaseRabbitCheck):
  	"""
  	performs a nagios compliant check on a single queue and
  	attempts to catch all errors. expected usage is with a critical threshold of 0
  	"""
  
  	vhost = make_option("--vhost", dest="vhost", help="RabbitMQ vhost", type="string", default='%2F')
  	queue = make_option("--queue", dest="queue", help="Name of the queue in inspect", type="string")
  
  
  	def makeUrl(self):
  		"""
  		forms self.url, a correct url to polling a rabbit queue
  		"""
  		try:
  			self.url = "http://%s:%s/api/queues/%s/%s" % (self.options.hostname, self.options.port, self.options.vhost, self.options.queue)
  			return True
  		except Exception, e:
  			self.rabbit_error = 3
  			self.rabbit_note = "problem forming api url:", e
  		return False
  
  	def testOptions(self):
  		"""
  		returns false if necessary options aren't present
  		"""
  		if not self.options.hostname or not self.options.port or not self.options.vhost or not self.options.queue:
  			return False
  		return True
  
          def setPerformanceData(self, data, result):
  
                  if data.get('messages'):
                          result.set_perf_data(self.queue + "_messages", data['messages'])
                          result.set_perf_data(self.queue + "_rate", data['messages_details']['rate'])
                          result.set_perf_data(self.queue + "_consumers", data['consumers'])
                          result.set_perf_data("rabbit_error", self.rabbit_error)
                  else:
                          result.set_perf_data(self.queue + "_messages", 0)
                          result.set_perf_data(self.queue + "_rate", 0)
                          result.set_perf_data(self.queue + "_consumers", data['consumers'])
                          result.set_perf_data("rabbit_error", self.rabbit_error)
  
                  return result
  
          def parseResult(self, data):
                  self.queue = self.options.queue
                  if data.get('messages'):
                          result = self.response_for_value(data['messages'])
                          result.message = ' found ' + str(data['messages']) + ' messages'
                          self.rabbit_note = ' found ' + str(data['messages']) + ' messages'
                  else:
                          result = self.response_for_value(0)
                          result.message = ' No messages found in queue'
                          self.rabbit_note = result.message
                  return result
  
  
  if __name__ == "__main__":
  	obj = RabbitQueueCheck()
  	obj.check().exit()
  
subject: Update to handle when NO messages exist for a specified queue.