<commit_before>#!/usr/bin/env python
#
# Copyright (c) 2012 <NAME> <<EMAIL>>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

import optparse
import pynagios
import re
import subprocess

class CarpDemotionCheck(pynagios.Plugin):
    int_group = optparse.make_option("--interface-group", dest="int_group",
                                     type="string", default="carp")

    def check(self):
        int_group = self.options.int_group
        try:
            output = subprocess.check_output(('ifconfig', '-g', int_group),
                                             stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as e:
            message = "Error finding count: " + e.output.replace('\n', '')
            response = pynagios.response.Response(pynagios.UNKNOWN, message)
        else:
            re_match = re.search(r'carp demote count (\d+)', output)
            if re_match:
                count = int(re_match.group(1))
                message = "%s demote counter is %d" % (int_group, count)
                response = self.response_for_value(count, message)
            else:
                message = "RE could not match output: " + output.replace('\n', '')
                response = pynagios.response.Response(pynagios.UNKNOWN, message)
    
        return response

if __name__ == '__main__':
    CarpDemotionCheck().check().exit()<commit_msg>fixes for pylint<commit_after>#!/usr/bin/env python
#
# Copyright (c) 2012 <NAME> <<EMAIL>>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

"Nagios Plugin to check interface group demotion counter"

import optparse
import pynagios
import re
import subprocess

class CarpDemotionCheck(pynagios.Plugin):
    "pynagios Plugin that executes ifconfig(1) to determine demote count"
    int_group = optparse.make_option("--interface-group", dest="int_group",
                                     type="string", default="carp")

    def check(self):
        int_group = self.options.int_group
        try:
            output = str(subprocess.check_output(('ifconfig', '-g', int_group),
                                             stderr=subprocess.STDOUT))
        except subprocess.CalledProcessError as error:
            message = "Error finding count: " + error.output.replace('\n', '')
            response = pynagios.response.Response(pynagios.UNKNOWN, message)
        else:
            re_match = re.search(r'carp demote count (\d+)', output)
            if re_match:
                count = int(re_match.group(1))
                message = "%s demote counter is %d" % (int_group, count)
                response = self.response_for_value(count, message)
            else:
                message = "Could not match output: " + output.replace('\n', '')
                response = pynagios.response.Response(pynagios.UNKNOWN, message)

        return response

if __name__ == '__main__':
    CarpDemotionCheck().check().exit()
{'fraction_non_alphanumeric': 0.08975563909774437, 'fraction_numerical': 0.0025845864661654134, 'mean_word_length': 2.760600706713781, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2600292', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1123, 'n_words': 405}