def main():
    """Plugin: check_asa_connections."""
    argparser = SnmpArguments(description)
    argparser.parser.add_argument("-w", help="Number of connections to report warning state", type=int)
    argparser.parser.add_argument("-c", help="Number of connections to report critical state", type=int)

    args = argparser.parser.parse_nelmon_args()
    snmp = NelmonSnmp(args)

    current_connections = O.cfwConnectionStatValue + ".40.6"
    connections = snmp.get_value(current_connections)

    if not args.c or not args.w:
        nelmon_exit(C.UNKNOWN, "Use -w or -c")

    if args.c <= connections:
        exit_code = C.CRITICAL
        exit_string = "%d connections" % connections
    elif args.w <= connections:
        exit_code = C.WARNING
        exit_string = "%d connections" % connections
    else:
        exit_code = C.OK
        exit_string = "%d connections" % connections

    if args.c and args.w:
        perf_data = "connections=%s;%s;%s" % (connections, args.w, args.c)
    else:
        perf_data = "connections=%s" % connections

    nelmon_exit(exit_code, exit_string, perf_data=perf_data)
def main():
    """Plugin: check_asa_connections."""
    argparser = SnmpArguments(description)
    argparser.parser.add_argument(
        '-w', help='Number of connections to report warning state', type=int)
    argparser.parser.add_argument(
        '-c', help='Number of connections to report critical state', type=int)

    args = argparser.parser.parse_nelmon_args()
    snmp = NelmonSnmp(args)

    current_connections = O.cfwConnectionStatValue + ".40.6"
    connections = snmp.get_value(current_connections)

    if not args.c or not args.w:
        nelmon_exit(C.UNKNOWN, 'Use -w or -c')

    if args.c <= connections:
        exit_code = C.CRITICAL
        exit_string = "%d connections" % connections
    elif args.w <= connections:
        exit_code = C.WARNING
        exit_string = "%d connections" % connections
    else:
        exit_code = C.OK
        exit_string = "%d connections" % connections

    if args.c and args.w:
        perf_data = 'connections=%s;%s;%s' % (connections, args.w, args.c)
    else:
        perf_data = 'connections=%s' % connections

    nelmon_exit(exit_code, exit_string, perf_data=perf_data)
Exemple #3
0
def main():
    """Plugin: check_uptime."""
    argparser = SnmpArguments(description)
    args = argparser.parser.parse_nelmon_args()
    snmp = NelmonSnmp(args)
    uptime = snmp.get_value(O.sysUpTime + '.0')
    nelmon_exit(C.OK, uptime)
Exemple #4
0
def main():
    """Plugin: check_uptime."""
    argparser = SnmpArguments(description)
    args = argparser.parser.parse_nelmon_args()
    snmp = NelmonSnmp(args)
    uptime = snmp.get_value(O.sysUpTime + '.0')
    nelmon_exit(C.OK, uptime)
Exemple #5
0
    def parse_nelmon_args(self):
        sys_args = sys.argv[1:]
        choose_output = False
        for sys_arg in sys_args:
            if choose_output:
                if sys_arg == 'with_status':
                    NelmonGlobals(OUTPUT_FORMAT='with_status')
                choose_output = False
            if sys_arg == '-O':
                choose_output = True
        if '-V' in sys_args:
            output = '%s - v%s (Nelmon - v%s)' % (
                C.CURRENT_PLUGIN, NelmonGlobals.PLUGIN_VERSION, C.NELMON_VERSION)
            nelmon_exit(C.OK, output)
        args = self.parse_args()

        return args
Exemple #6
0
    def parse_nelmon_args(self):
        sys_args = sys.argv[1:]
        choose_output = False
        for sys_arg in sys_args:
            if choose_output:
                if sys_arg == 'with_status':
                    NelmonGlobals(OUTPUT_FORMAT='with_status')
                choose_output = False
            if sys_arg == '-O':
                choose_output = True
        if '-V' in sys_args:
            output = '%s - v%s (Nelmon - v%s)' % (C.CURRENT_PLUGIN,
                                                  NelmonGlobals.PLUGIN_VERSION,
                                                  C.NELMON_VERSION)
            nelmon_exit(C.OK, output)
        args = self.parse_args()

        return args
def main():
    """Plugin: check_admin_up_oper_down."""
    argparser = SnmpArguments(description)
    argparser.parser.add_argument('-w', action='store_true',
                                  help='Return Warning if interfaces are down')
    argparser.parser.add_argument('-c', action='store_true',
                                  help='Return Critical if interfaces are down')

    args = argparser.parser.parse_nelmon_args()

    if args.c:
        exit_status = C.CRITICAL
    elif args.w:
        exit_status = C.WARNING
    else:
        nelmon_exit(C.UNKNOWN, 'Use -w or -c')

    snmp = NelmonSnmp(args)

    oidlist = []
    oidlist.append(O.ifAdminStatus)
    oidlist.append(O.ifOperStatus)

    var_table = snmp.getnext(*oidlist)

    admin_up = []
    oper_down = []

    for var_binds in var_table:

        for oid, value in var_binds:
            if O.ifAdminStatus in oid and value == 1:
                ifIndex = int(oid.rsplit('.', 1)[-1])
                admin_up.append(ifIndex)
            if O.ifOperStatus in oid and value == 2:
                ifIndex = int(oid.rsplit('.', 1)[-1])
                oper_down.append(ifIndex)

    down_interfaces = list(set(admin_up) & set(oper_down))
    if len(down_interfaces) == 0:
        nelmon_exit(C.OK, 'No interfaces down')

    oidlist = []
    interface_descr = {}
    interface_alias = {}
    for ifIndex in down_interfaces:
        oidlist.append(O.ifDescr + "." + str(ifIndex))
        oidlist.append(O.ifAlias + "." + str(ifIndex))
    var_binds = snmp.get(*oidlist)
    for oid, value in var_binds:
        if O.ifDescr in oid:
            ifIndex = int(oid.rsplit('.', 1)[-1])
            interface_descr[ifIndex] = value
        if O.ifAlias in oid:
            ifIndex = int(oid.rsplit('.', 1)[-1])
            interface_alias[ifIndex] = value
    return_string = []

    if len(down_interfaces) > 1:
        return_string.append("%d interfaces down" % (len(down_interfaces)))

    for ifIndex in down_interfaces:
        if len(str(interface_alias[ifIndex])) > 0:
            return_string.append(str(interface_descr[ifIndex]) + " - " + str(interface_alias[ifIndex]))
        else:
            return_string.append(str(interface_descr[ifIndex]))

    nelmon_exit(exit_status, return_string)
Exemple #8
0
 def _verify_snmp_arguments(self, args):
     if args.P == "2c" and args.C is None:
         nelmon_exit(C.UNKNOWN, 'Specify community when using SNMP 2c')
     if args.P == "3" and args.U is None:
         nelmon_exit(C.UNKNOWN, 'Specify username when using SNMP 3')
     if args.P == "3" and args.L is None:
         nelmon_exit(C.UNKNOWN, 'Specify security level when using SNMP 3')
     if args.L == "authNoPriv" and args.a is None:
         nelmon_exit(C.UNKNOWN,
                     'Specify authentication protocol when using authNoPriv')
     if args.L == "authNoPriv" and args.A is None:
         nelmon_exit(C.UNKNOWN,
                     'Specify authentication password when using authNoPriv')
     if args.L == "authPriv" and args.a is None:
         nelmon_exit(C.UNKNOWN,
                     'Specify authentication protocol when using authPriv')
     if args.L == "authPriv" and args.A is None:
         nelmon_exit(C.UNKNOWN,
                     'Specify authentication password when using authPriv')
     if args.L == "authPriv" and args.x is None:
         nelmon_exit(C.UNKNOWN, 'Specify privacy protocol when using authPriv')
     if args.L == "authPriv" and args.X is None:
         nelmon_exit(C.UNKNOWN, 'Specify privacy password when using authPriv')
Exemple #9
0
 def _raise_error(self, ErrorType, error_data):
     nelmon_exit(C.CRITICAL, error_data)
Exemple #10
0
 def _verify_snmp_arguments(self, args):
     if args.P == "2c" and args.C is None:
         nelmon_exit(C.UNKNOWN, 'Specify community when using SNMP 2c')
     if args.P == "3" and args.U is None:
         nelmon_exit(C.UNKNOWN, 'Specify username when using SNMP 3')
     if args.P == "3" and args.L is None:
         nelmon_exit(C.UNKNOWN, 'Specify security level when using SNMP 3')
     if args.L == "authNoPriv" and args.a is None:
         nelmon_exit(
             C.UNKNOWN,
             'Specify authentication protocol when using authNoPriv')
     if args.L == "authNoPriv" and args.A is None:
         nelmon_exit(
             C.UNKNOWN,
             'Specify authentication password when using authNoPriv')
     if args.L == "authPriv" and args.a is None:
         nelmon_exit(C.UNKNOWN,
                     'Specify authentication protocol when using authPriv')
     if args.L == "authPriv" and args.A is None:
         nelmon_exit(C.UNKNOWN,
                     'Specify authentication password when using authPriv')
     if args.L == "authPriv" and args.x is None:
         nelmon_exit(C.UNKNOWN,
                     'Specify privacy protocol when using authPriv')
     if args.L == "authPriv" and args.X is None:
         nelmon_exit(C.UNKNOWN,
                     'Specify privacy password when using authPriv')
Exemple #11
0
 def _raise_error(self, ErrorType, error_data):
     nelmon_exit(C.CRITICAL, error_data)
def main():
    """Plugin: check_admin_up_oper_down."""
    argparser = SnmpArguments(description)
    argparser.parser.add_argument('-w',
                                  action='store_true',
                                  help='Return Warning if interfaces are down')
    argparser.parser.add_argument(
        '-c',
        action='store_true',
        help='Return Critical if interfaces are down')
    argparser.parser.add_argument(
        '-d',
        '--descr',
        dest='ifdescr_arg',
        default=None,
        const=None,
        help='Search over Interface descr with regex'
        'example: GigabitEthernet(\d+)/0/(4[78]|[5][0-2])'
        'matches any of: GigabitEthernetx/0/47,48,50,51,52')
    argparser.parser.add_argument(
        '-al',
        '--alias',
        dest='ifalias_arg',
        default=None,
        const=None,
        help='Search over Interface alias with regex'
        'example: UPLINK'
        'matches any interfaces with keyword UPLINK on its alias')
    argparser.parser.add_argument(
        '-id',
        '--ignore_descr',
        dest='ifdescr_ignore_arg',
        default=None,
        const=None,
        help='Search over Interface ifDescr with regex and ignores that'
        'example: Stack')

    args = argparser.parser.parse_nelmon_args()

    if args.c:
        exit_status = C.CRITICAL
    elif args.w:
        exit_status = C.WARNING
    else:
        nelmon_exit(C.UNKNOWN, 'Use -w or -c')

    ifdescr_arg = args.ifdescr_arg
    ifalias_arg = args.ifalias_arg
    ifdescr_ignore_arg = args.ifdescr_ignore_arg

    snmp = NelmonSnmp(args)

    oidlist = []
    oidlist.append(O.ifAdminStatus)
    oidlist.append(O.ifOperStatus)

    var_table = snmp.getnext(*oidlist)

    admin_up = []
    oper_down = []

    for var_binds in var_table:

        for oid, value in var_binds:
            if O.ifAdminStatus in oid and value == 1:
                ifIndex = int(oid.rsplit('.', 1)[-1])
                admin_up.append(ifIndex)
            if O.ifOperStatus in oid and value == 2:
                ifIndex = int(oid.rsplit('.', 1)[-1])
                oper_down.append(ifIndex)

    down_interfaces = list(set(admin_up) & set(oper_down))
    if len(down_interfaces) == 0:
        nelmon_exit(C.OK, 'No interfaces down')

    oidlist = []
    interface_descr = {}
    interface_alias = {}
    for ifIndex in down_interfaces:
        oidlist.append(O.ifDescr + "." + str(ifIndex))
        oidlist.append(O.ifAlias + "." + str(ifIndex))
    var_binds = snmp.get(*oidlist)
    for oid, value in var_binds:
        if O.ifDescr in oid:
            ifIndex = int(oid.rsplit('.', 1)[-1])
            interface_descr[ifIndex] = value
        if O.ifAlias in oid:
            ifIndex = int(oid.rsplit('.', 1)[-1])
            interface_alias[ifIndex] = value
    return_string = []

    # Change the down_interfaces only to those that ifDescr matches regex passed to ifdescr_arg
    if ifdescr_arg:
        down_interfaces = []
        for ifIndex, ifDescr in interface_descr.items():
            # Add the regex from -d command, like: GigabitEthernet(\d+)/0/(4[78]|[5][0-2])
            ifdescr_regex = re.compile(ifdescr_arg)
            # Only add to down_interfaces if regex matches
            if ifdescr_regex.search(ifDescr):
                down_interfaces.append(ifIndex)

    # Change the down_interfaces only to those that ifAlias matches regex passed to ifalias_arg
    if ifalias_arg:
        down_interfaces = []
        if interface_alias:
            for ifIndex, ifAlias in interface_alias.items():
                # Add the regex from -al command, like: UPLINK
                ifalias_regex = re.compile(ifalias_arg)
                # Only add to down_interfaces if regex matches
                if ifalias_regex.search(ifAlias):
                    down_interfaces.append(ifIndex)

    # Change the down_interfaces only to those that ifDescr doesn't match regex passed to ifdescr_ignore_arg
    if ifdescr_ignore_arg:
        for ifIndex, ifDescr in interface_descr.items():
            # Add the regex from --id command, like: GigabitEthernet(\d+)/0/(4[78]|[5][0-2]) or Stack
            ifdescr_regex = re.compile(ifdescr_ignore_arg)
            # Remove from down_interfaces if regex matches
            if ifdescr_regex.search(ifDescr):
                down_interfaces.remove(ifIndex)

    if len(down_interfaces) > 0:
        return_string.append("%d interfaces down" % (len(down_interfaces)))
    else:
        nelmon_exit(C.OK, 'No interfaces down')

    for ifIndex in down_interfaces:
        if len(str(interface_alias[ifIndex])) > 0:
            return_string.append(
                str(interface_descr[ifIndex]) + " - " +
                str(interface_alias[ifIndex]))
        else:
            return_string.append(str(interface_descr[ifIndex]))

    nelmon_exit(exit_status, return_string)
Exemple #13
0
def main():

    argparser = SnmpArguments(description)

    args = argparser.parser.parse_nelmon_args()
    snmp = NelmonSnmp(args)

    hostinfo = HostInfo(snmp)
    hostinfo.get_vendor()

    if hostinfo.vendor != 'cisco':
        nelmon_exit(C.UNKNOWN, '%s v%s only works with Cisco devices' % (C.CURRENT_PLUGIN, NelmonGlobals.PLUGIN_VERSION))

    env_tables = snmp.getnext(O.ciscoEnvMonObjects)
    volt_sensors = {}
    temp_sensors = {}
    fan_sensors = {}
    pw_sensors = {}
    s = SensorCollection()
    for env_table in env_tables:
        for oid, value in env_table:
            if O.ciscoEnvMonVoltageStatusTable in oid:
                sensor_id = oid.rsplit('.', 1)[-1]
                if not sensor_id in volt_sensors.keys():
                    volt_sensors[sensor_id] = Sensor(sensor_id)
                if O.ciscoEnvMonVoltageStatusDescr in oid:
                    volt_sensors[sensor_id].set_description(value)
                if O.ciscoEnvMonVoltageStatusValue in oid:
                    volt_sensors[sensor_id].set_value(value)
                if O.ciscoEnvMonVoltageState in oid:
                    volt_sensors[sensor_id].set_state(value)
            if O.ciscoEnvMonTemperatureStatusTable in oid:
                sensor_id = oid.rsplit('.', 1)[-1]
                if not sensor_id in temp_sensors.keys():
                    temp_sensors[sensor_id] = Sensor(sensor_id)
                if O.ciscoEnvMonTemperatureStatusDescr in oid:
                    temp_sensors[sensor_id].set_description(value)
                if O.ciscoEnvMonTemperatureStatusValue in oid:
                    temp_sensors[sensor_id].set_value(value)
                if O.ciscoEnvMonTemperatureState in oid:
                    temp_sensors[sensor_id].set_state(value)
            if O.ciscoEnvMonFanStatusTable in oid:
                sensor_id = oid.rsplit('.', 1)[-1]
                if not sensor_id in fan_sensors.keys():
                    fan_sensors[sensor_id] = Sensor(sensor_id)
                if O.ciscoEnvMonFanStatusDescr in oid:
                    fan_sensors[sensor_id].set_description(value)
                if O.ciscoEnvMonFanState in oid:
                    fan_sensors[sensor_id].set_state(value)
            if O.ciscoEnvMonSupplyStatusTable in oid:
                sensor_id = oid.rsplit('.', 1)[-1]
                if not sensor_id in pw_sensors.keys():
                    pw_sensors[sensor_id] = Sensor(sensor_id)
                if O.ciscoEnvMonSupplyStatusDescr in oid:
                    pw_sensors[sensor_id].set_description(value)
                if O.ciscoEnvMonSupplyState in oid:
                    pw_sensors[sensor_id].set_state(value)

    for sensor in volt_sensors:
        s.add_sensor('volt', volt_sensors[sensor].description, volt_sensors[sensor].state)
    for sensor in temp_sensors:
        s.add_sensor('temp', temp_sensors[sensor].description, temp_sensors[sensor].state)
    for sensor in fan_sensors:
        s.add_sensor('fan', fan_sensors[sensor].description, fan_sensors[sensor].state)
    for sensor in pw_sensors:
        s.add_sensor('pw', pw_sensors[sensor].description, pw_sensors[sensor].state)

    s.set_message()
    nelmon_exit(s.status, s.output)
Exemple #14
0
 def error(self, message):
     nelmon_exit(C.UNKNOWN, '%s: error: %s\n' % (self.prog, message))
def main():
    """Plugin: check_admin_up_oper_down."""
    argparser = SnmpArguments(description)
    argparser.parser.add_argument('-w',
                                  action='store_true',
                                  help='Return Warning if interfaces are down')
    argparser.parser.add_argument(
        '-c',
        action='store_true',
        help='Return Critical if interfaces are down')

    args = argparser.parser.parse_nelmon_args()

    if args.c:
        exit_status = C.CRITICAL
    elif args.w:
        exit_status = C.WARNING
    else:
        nelmon_exit(C.UNKNOWN, 'Use -w or -c')

    snmp = NelmonSnmp(args)

    oidlist = []
    oidlist.append(O.ifAdminStatus)
    oidlist.append(O.ifOperStatus)

    var_table = snmp.getnext(*oidlist)

    admin_up = []
    oper_down = []

    for var_binds in var_table:

        for oid, value in var_binds:
            if O.ifAdminStatus in oid and value == 1:
                ifIndex = int(oid.rsplit('.', 1)[-1])
                admin_up.append(ifIndex)
            if O.ifOperStatus in oid and value == 2:
                ifIndex = int(oid.rsplit('.', 1)[-1])
                oper_down.append(ifIndex)

    down_interfaces = list(set(admin_up) & set(oper_down))
    if len(down_interfaces) == 0:
        nelmon_exit(C.OK, 'No interfaces down')

    oidlist = []
    interface_descr = {}
    interface_alias = {}
    for ifIndex in down_interfaces:
        oidlist.append(O.ifDescr + "." + str(ifIndex))
        oidlist.append(O.ifAlias + "." + str(ifIndex))
    var_binds = snmp.get(*oidlist)
    for oid, value in var_binds:
        if O.ifDescr in oid:
            ifIndex = int(oid.rsplit('.', 1)[-1])
            interface_descr[ifIndex] = value
        if O.ifAlias in oid:
            ifIndex = int(oid.rsplit('.', 1)[-1])
            interface_alias[ifIndex] = value
    return_string = []

    if len(down_interfaces) > 1:
        return_string.append("%d interfaces down" % (len(down_interfaces)))

    for ifIndex in down_interfaces:
        if len(str(interface_alias[ifIndex])) > 0:
            return_string.append(
                str(interface_descr[ifIndex]) + " - " +
                str(interface_alias[ifIndex]))
        else:
            return_string.append(str(interface_descr[ifIndex]))

    nelmon_exit(exit_status, return_string)
Exemple #16
0
 def error(self, message):
     nelmon_exit(C.UNKNOWN, '%s: error: %s\n' % (self.prog, message))
Exemple #17
0
def main():
    argparser = SnmpArguments(description)
    argparser.parser.add_argument(
        '-d', help="Directory containing yaml version files")
    args = argparser.parser.parse_nelmon_args()
    snmp = NelmonSnmp(args)
    hostinfo = HostInfo(snmp)
    hostinfo.get_version()

    if hostinfo.version == 'UNKNOWN':
        exit_str = ['Unable to determine device version']
        exit_str.append('Vendor: %s' % hostinfo.vendor)
        exit_str.append('OS: %s' % hostinfo.os)
        exit_str.append('Version: %s' % hostinfo.version)
        exit_str.append('*******************************')
        exit_str.append("Your version of Nelsnmp does't support this device")
        exit_str.append('please check:')
        exit_str.append('http://networklore.com/nelsnmp-hostinfo/')
        nelmon_exit(C.UNKNOWN, exit_str)

    if args.d:
        yaml_file = '%s/%s_%s.yml' % (args.d, hostinfo.vendor, hostinfo.os)
    else:
        nelmon_exit(C.OK, hostinfo.version)

    if not os.path.isfile(yaml_file):
        nelmon_exit(C.UNKNOWN, 'Unable to find file: %s' % yaml_file)

    data = None
    with open(yaml_file, 'r') as f:
        data = yaml.load(f.read())

    if data is None:
        nelmon_exit(C.UNKNOWN, 'Unable to parse %s' % yaml_file)

    declared_versions = []
    for policy in data:
        if data[policy] is not None:
            for version in data[policy]:
                declared_versions.append(version)
                if hostinfo.version == version:
                    match_policy = policy

    hits = declared_versions.count(hostinfo.version)
    if hits == 0:
        nelmon_exit(C.UNKNOWN,
                    '%s not declared in %s' % (hostinfo.version, yaml_file))
    elif hits > 1:
        nelmon_exit(
            C.UNKNOWN, '%s is declared  %s times in %s' %
            (hostinfo.version, hits, yaml_file))
    else:
        if match_policy == 'approved':
            if data[match_policy][hostinfo.version]:
                nelmon_exit(
                    C.OK, '%s - %s' %
                    (hostinfo.version, data[match_policy][hostinfo.version]))
            else:
                nelmon_exit(C.OK, hostinfo.version)
        elif match_policy == 'critical':
            if data[match_policy][hostinfo.version]:
                nelmon_exit(
                    C.CRITICAL, '%s - %s (critical)' %
                    (hostinfo.version, data[match_policy][hostinfo.version]))
            else:
                nelmon_exit(C.CRITICAL, '%s - (critical)' % hostinfo.version)
        elif match_policy == 'vulnerable':
            if data[match_policy][hostinfo.version]:
                nelmon_exit(
                    C.WARNING, '%s - %s (vulnerable)' %
                    (hostinfo.version, data[match_policy][hostinfo.version]))
            else:
                nelmon_exit(C.WARNING, '%s - (warning)' % hostinfo.version)
        elif match_policy == 'obsolete':
            if data[match_policy][hostinfo.version]:
                nelmon_exit(
                    C.WARNING, '%s - %s (obsolete)' %
                    (hostinfo.version, data[match_policy][hostinfo.version]))
            else:
                nelmon_exit(C.WARNING, '%s - (obsolete)' % hostinfo.version)
        else:
            nelmon_exit(
                C.UNKNOWN, '%s is under unknown policy: %s' %
                (hostinfo.version, match_policy))

    nelmon_exit(C.OK, hostinfo.version)
Exemple #18
0
def main():
    """Plugin: check_version."""
    argparser = SnmpArguments(description)
    argparser.parser.add_argument(
        '-d',
        help="Directory containing yaml version files")
    args = argparser.parser.parse_nelmon_args()
    snmp = NelmonSnmp(args)
    hostinfo = HostInfo(snmp)
    hostinfo.get_version()

    if hostinfo.version == 'UNKNOWN':
        exit_str = ['Unable to determine device version']
        exit_str.append('Vendor: %s' % hostinfo.vendor)
        exit_str.append('OS: %s' % hostinfo.os)
        exit_str.append('Version: %s' % hostinfo.version)
        exit_str.append('*******************************')
        exit_str.append("Your version of Nelsnmp does't support this device")
        exit_str.append('please check:')
        exit_str.append('http://networklore.com/nelsnmp-hostinfo/')
        nelmon_exit(C.UNKNOWN, exit_str)

    if args.d:
        yaml_file = '%s/%s_%s.yml' % (args.d, hostinfo.vendor, hostinfo.os)
    else:
        nelmon_exit(C.OK, hostinfo.version)

    if not os.path.isfile(yaml_file):
        nelmon_exit(C.UNKNOWN, 'Unable to find file: %s' % yaml_file)

    data = None
    with open(yaml_file, 'r') as f:
        data = yaml.load(f.read())

    if data is None:
        nelmon_exit(C.UNKNOWN, 'Unable to parse %s' % yaml_file)

    declared_versions = []
    for policy in data:
        if data[policy] is not None:
            for version in data[policy]:
                declared_versions.append(version)
                if hostinfo.version == version:
                    match_policy = policy

    hits = declared_versions.count(hostinfo.version)
    if hits == 0:
        nelmon_exit(
            C.UNKNOWN, '%s not declared in %s' % (hostinfo.version, yaml_file))
    elif hits > 1:
        nelmon_exit(
            C.UNKNOWN,
            '%s is declared  %s times in %s' % (hostinfo.version,
                                                hits, yaml_file))
    else:
        if match_policy == 'approved':
            if data[match_policy][hostinfo.version]:
                nelmon_exit(
                    C.OK,
                    '%s - %s' % (hostinfo.version,
                                 data[match_policy][hostinfo.version])
                )
            else:
                nelmon_exit(C.OK, hostinfo.version)
        elif match_policy == 'critical':
            if data[match_policy][hostinfo.version]:
                nelmon_exit(
                    C.CRITICAL,
                    '%s - %s (critical)' % (
                        hostinfo.version,
                        data[match_policy][hostinfo.version])
                )
            else:
                nelmon_exit(C.CRITICAL, '%s - (critical)' % hostinfo.version)
        elif match_policy == 'vulnerable':
            if data[match_policy][hostinfo.version]:
                nelmon_exit(
                    C.WARNING,
                    '%s - %s (vulnerable)' % (
                        hostinfo.version,
                        data[match_policy][hostinfo.version])
                )
            else:
                nelmon_exit(C.WARNING, '%s - (warning)' % hostinfo.version)
        elif match_policy == 'obsolete':
            if data[match_policy][hostinfo.version]:
                nelmon_exit(
                    C.WARNING,
                    '%s - %s (obsolete)' % (
                        hostinfo.version,
                        data[match_policy][hostinfo.version])
                )
            else:
                nelmon_exit(C.WARNING, '%s - (obsolete)' % hostinfo.version)
        else:
            nelmon_exit(C.UNKNOWN,
                        '%s is under unknown policy: %s' % (
                            hostinfo.version, match_policy))

    nelmon_exit(C.OK, hostinfo.version)