<commit_before>#!/usr/bin/python

"""
Check HTTP JSON Nagios Plugin

Generic Nagios plugin which checks json values from a given endpoint against argument specified rules
and determines the status and performance data for that service.
"""

import httplib, urllib, urllib2, base64
import json
import argparse
import sys
from pprint import pprint
from urllib2 import HTTPError
from urllib2 import URLError

# TEST = False


OK_CODE = 0
WARNING_CODE = 1
CRITICAL_CODE = 2
UNKNOWN_CODE = 3

class NagiosHelper:
	"""Help with Nagios specific status string formatting."""
	message_prefixes = {OK_CODE: 'OK', WARNING_CODE: 'WARNING', CRITICAL_CODE: 'CRITICAL', UNKNOWN_CODE: 'UNKNOWN'}
	performance_data = ''
	warning_message = ''
	critical_message = ''
	unknown_message = ''

	def getMessage(self):
		"""Build a status-prefixed message with optional performance data generated externally"""
		text = "%s: Status %s." % (self.message_prefixes[self.getCode()], self.message_prefixes[self.getCode()])
		text += self.warning_message
		text += self.critical_message
		text += self.unknown_message
		if self.performance_data:
			text += "|%s" % self.performance_data
		return text

	def getCode(self):
		code = OK_CODE
		if (self.warning_message != ''):
			code = WARNING_CODE
		if (self.critical_message != ''):
			code = CRITICAL_CODE
		if (self.unknown_message != ''):
			code = UNKNOWN_CODE
		return code

	def append_warning(self, warning_message):
		self.warning_message += warning_message
	def append_critical(self, critical_message):
		self.critical_message += critical_message
	def append_unknown(self, unknown_message):
		self.critical_message += critical_message
	def append_metrics(self, (performance_data, warning_message, critical_message)):
		self.performance_data += performance_data
		self.append_warning(warning_message)
		self.append_critical(critical_message)
<commit_msg>fix variable error<commit_after>#!/usr/bin/python

"""
Check HTTP JSON Nagios Plugin

Generic Nagios plugin which checks json values from a given endpoint against argument specified rules
and determines the status and performance data for that service.
"""

import httplib, urllib, urllib2, base64
import json
import argparse
import sys
from pprint import pprint
from urllib2 import HTTPError
from urllib2 import URLError

# TEST = False


OK_CODE = 0
WARNING_CODE = 1
CRITICAL_CODE = 2
UNKNOWN_CODE = 3

class NagiosHelper:
	"""Help with Nagios specific status string formatting."""
	message_prefixes = {OK_CODE: 'OK', WARNING_CODE: 'WARNING', CRITICAL_CODE: 'CRITICAL', UNKNOWN_CODE: 'UNKNOWN'}
	performance_data = ''
	warning_message = ''
	critical_message = ''
	unknown_message = ''

	def getMessage(self):
		"""Build a status-prefixed message with optional performance data generated externally"""
		text = "%s: Status %s." % (self.message_prefixes[self.getCode()], self.message_prefixes[self.getCode()])
		text += self.warning_message
		text += self.critical_message
		text += self.unknown_message
		if self.performance_data:
			text += "|%s" % self.performance_data
		return text

	def getCode(self):
		code = OK_CODE
		if (self.warning_message != ''):
			code = WARNING_CODE
		if (self.critical_message != ''):
			code = CRITICAL_CODE
		if (self.unknown_message != ''):
			code = UNKNOWN_CODE
		return code

	def append_warning(self, warning_message):
		self.warning_message += warning_message
	def append_critical(self, critical_message):
		self.critical_message += critical_message
	def append_unknown(self, unknown_message):
		self.critical_message += unknown_message
	def append_metrics(self, (performance_data, warning_message, critical_message)):
		self.performance_data += performance_data
		self.append_warning(warning_message)
		self.append_critical(critical_message)

{'fraction_non_alphanumeric': 0.09718534253850239, 'fraction_numerical': 0.004779607010090282, 'mean_word_length': 5.417376490630324, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5479068', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1134, 'n_words': 320}