def check_controller(sess):
    """
    check the status of the controller
    """
    controller_operational             = get_data(sess, operational_oid, helper)
    controller_availability            = get_data(sess, availability_oid, helper)
    controller_alarm                   = get_data(sess, alarm_oid, helper)
    
    # Add summary
    helper.add_summary("Controller Status")

    # Add all states to the long output
    helper.add_long_output("Controller Operational State: %s" % operational_states[int(controller_operational)])
    helper.add_long_output("Controller Availability State: %s" % availability_states[int(controller_availability)])
    helper.add_long_output("Controller Alarm State: %s" % alarm_states[int(controller_alarm)])

    # Operational State
    if controller_operational != "1" and controller_operational != "4":
        helper.status(critical)
        helper.add_summary("Controller Operational State: %s" % operational_states[int(controller_operational)])

    # Avaiability State
    if controller_availability != "3":
        helper.status(critical)
        helper.add_summary("Controller Availability State: %s" % availability_states[int(controller_availability)])

    # Alarm State
    if controller_alarm == "2":
        helper.status(warning)
        helper.add_summary("Controller Alarm State: %s" % alarm_states[int(controller_alarm)])
    if controller_alarm == "3" or controller_alarm == "4":
        helper.status(critical)
        helper.add_summary("Controller Alarm State: %s" % alarm_states[int(controller_alarm)])
def check_ressources(sess):
    """
    check the Ressources of the Fortinet Controller
    all thresholds are currently hard coded. should be fine.
    """
    # get the data
    cpu_value                    = get_data(sess, cpu_oid, helper)
    memory_value                 = get_data(sess, memory_oid, helper)
    filesystem_value             = get_data(sess, filesystem_oid, helper)

    helper.add_summary("Controller Status")
    helper.add_long_output("Controller Ressources - CPU: %s%%" % cpu_value)
    helper.add_metric("CPU", cpu_value, "0:90", "0:90", "", "", "%%")
    if int(cpu_value) > 90:
        helper.status(critical)
        helper.add_summary("Controller Ressources - CPU: %s%%" % cpu_value)

    helper.add_long_output("Memory: %s%%" % memory_value)
    helper.add_metric("Memory", memory_value, "0:90", "0:90", "", "", "%%")
    if int(memory_value) > 90:
        helper.add_summary("Memory: %s%%" % memory_value)
        helper.status(critical)
    
    helper.add_long_output("Filesystem: %s%%" % filesystem_value)
    helper.add_metric("Filesystem", filesystem_value, "0:90", "0:90", "", "", "%%")
    if int(filesystem_value) > 90:
        helper.add_summary("Filesystem: %s%%" % filesystem_value)
        helper.status(critical)
def check_ressources(sess):
    """
    check the Ressources of the Fortinet Controller
    all thresholds are currently hard coded. should be fine.
    """
    # get the data
    cpu_value = get_data(sess, cpu_oid, helper)
    memory_value = get_data(sess, memory_oid, helper)
    filesystem_value = get_data(sess, filesystem_oid, helper)

    helper.add_summary("Controller Status")
    helper.add_long_output("Controller Ressources - CPU: %s%%" % cpu_value)
    helper.add_metric("CPU", cpu_value, "0:90", "0:90", "", "", "%%")
    if int(cpu_value) > 90:
        helper.status(critical)
        helper.add_summary("Controller Ressources - CPU: %s%%" % cpu_value)

    helper.add_long_output("Memory: %s%%" % memory_value)
    helper.add_metric("Memory", memory_value, "0:90", "0:90", "", "", "%%")
    if int(memory_value) > 90:
        helper.add_summary("Memory: %s%%" % memory_value)
        helper.status(critical)

    helper.add_long_output("Filesystem: %s%%" % filesystem_value)
    helper.add_metric("Filesystem", filesystem_value, "0:90", "0:90", "", "",
                      "%%")
    if int(filesystem_value) > 90:
        helper.add_summary("Filesystem: %s%%" % filesystem_value)
        helper.status(critical)
def check_partition():
    """
    check the defined partition
    """
    
    all_index           = walk_data(sess, oid_hrStorageIndex, helper)[0]
    all_descriptions    = walk_data(sess, oid_hrStorageDescr, helper)[0]
    # we need the sucess flag for the error handling (partition found or not found)
    sucess              = False

    # here we zip all index and descriptions to have a list like
    # [('Physical memory', '1'), ('Virtual memory', '3'), ('/', '32'), ('/proc/xen', '33')]
    zipped = zip(all_index, all_descriptions)
    
    for partition in zipped:
        index       = partition[0]
        description = partition[1]
        
        if partition_found(disk, description):
            # we found the partition
            sucess = True

            # receive all values we need
            unit    =   float(get_data(sess, oid_hrStorageAllocationUnits + "." + index, helper))
            size    =   float(get_data(sess, oid_hrStorageSize + "." + index, helper))
            used    =   float(get_data(sess, oid_hrStorageUsed + "." + index, helper))

            if size == 0 or used == 0:
                # if the host return "0" as used or size, then we have a problem with the calculation (devision by zero)
                helper.exit(summary="Received value 0 as StorageSize or StorageUsed: calculation error", exit_code=unknown, perfdata='')

            # calculate the real size (size*unit) and convert the results to the target unit the user wants to see
            used_result     = convert_to_XX(calculate_real_size(used), unit, targetunit)
            size_result     = convert_to_XX(calculate_real_size(size), unit, targetunit)
            
            # calculation of the used percentage
            percent_used    = used_result / size_result * 100
            
            # we need a string and want only two decimals
            used_string     = str(float("{0:.2f}".format(used_result)))
            size_string     = str(float("{0:.2f}".format(size_result)))
            percent_string  = str(float("{0:.2f}".format(percent_used)))
            
            if percent_used < 0 or percent_used > 100:
                # just a validation that percent_used is not smaller then 0% or lager then 100%                
                helper.exit(summary="Calculation error - second counter overrun?", exit_code=unknown, perfdata='')                   
            
            # show the summary
            helper.add_summary("%s%% used (%s%s of %s%s) at '%s'" % (percent_string, used_string, targetunit, size_string, targetunit, description))
            # add the metric in percent. 
            helper.add_metric(label='percent used',value=percent_string, min="0", max="100", uom="%")
                    
    else:
        if not sucess:
            # if the partition was not found in the data output, we return an error
            helper.exit(summary="Partition '%s' not found" % disk, exit_code=unknown, perfdata='')
예제 #5
0
def test_get(capsys):
    """
    test of the get_data function
    """
    # run a get on a not existing host
    with pytest.raises(SystemExit):
        snmpSessionBaseClass.get_data(failSession, '.1', helper)
    out, err = capsys.readouterr()
    assert 'Unknown - snmpget failed - no data for host' in out
    # check if we receive the system uptime via snmp and compare it with the local uptime from /proc/uptime (except the last digit)
    assert snmpSessionBaseClass.get_data(
        session, '.1.3.6.1.2.1.25.1.1.0', helper)[:-2]\
        == get_system_uptime()[:-2]
def check_outlet(sess):
    """
    check the status of the specified outlet
    """
    outlet_name = get_data(sess, oid_outlet_name, helper)
    outlet_state = get_data(sess, oid_outlet_state, helper)
    outlet_real_state = states[int(outlet_state)]

    # here we check if the outlet is powered on
    if outlet_real_state != "on":
        helper.status(critical)

    # print the status
    helper.add_summary("Outlet %s - '%s' is: %s" %
                       (number, outlet_name, outlet_real_state.upper()))
def check_environment_temperature(the_session, the_helper, the_snmp_value, the_unit=1):
    """
    OID .1.3.6.1.4.1.318.1.1.10.2.3.2.1.4.1
    MIB Excerpt
    The current temperature reading from the probe displayed
    in the units shown in the 'iemStatusProbeTempUnits' OID
    (Celsius or Fahrenheit).

    Description of unit OID
    OID .1.3.6.1.4.1.318.1.1.10.2.3.2.1.5
    The temperature scale used to display the temperature
    thresholds of the probe, Celsius(1) or Fahrenheit(2).
    This setting is based on the system preferences
    configuration in the agent.    
    """

    a_snmp_unit = snmpSessionBaseClass.get_data(
        the_session,
        apc_oid_environment_temperature_unit,
        the_helper)
    snmp_units = {
        '1' : 'C',
        '2' : 'F'
        }
    a_unit = snmp_units.get(a_snmp_unit, 'UNKNOWN_UNIT')

    the_helper.add_metric(
        label=the_helper.options.type,
        value=the_snmp_value,
        warn=the_helper.options.warning,
        crit=the_helper.options.critical,
        uom=a_unit)

    the_helper.check_all_metrics()
    the_helper.set_summary("Current environmental temperature is {}{}".format(the_snmp_value, a_unit))
def check_environment_temperature(the_session,
                                  the_helper,
                                  the_snmp_value,
                                  the_unit=1):
    """
    OID .1.3.6.1.4.1.318.1.1.10.2.3.2.1.4.1
    MIB Excerpt
    The current temperature reading from the probe displayed
    in the units shown in the 'iemStatusProbeTempUnits' OID
    (Celsius or Fahrenheit).

    Description of unit OID
    OID .1.3.6.1.4.1.318.1.1.10.2.3.2.1.5
    The temperature scale used to display the temperature
    thresholds of the probe, Celsius(1) or Fahrenheit(2).
    This setting is based on the system preferences
    configuration in the agent.    
    """

    a_snmp_unit = snmpSessionBaseClass.get_data(
        the_session, apc_oid_environment_temperature_unit, the_helper)
    snmp_units = {'1': 'C', '2': 'F'}
    a_unit = snmp_units.get(a_snmp_unit, 'UNKNOWN_UNIT')

    the_helper.add_metric(label=the_helper.options.type,
                          value=the_snmp_value,
                          warn=the_helper.options.warning,
                          crit=the_helper.options.critical,
                          uom=a_unit)

    the_helper.check_all_metrics()
    the_helper.set_summary("Current environmental temperature is {}{}".format(
        the_snmp_value, a_unit))
예제 #9
0
def check_server_power():
    """
    Check if the server is powered on
    Skip this check, if the --noPowerState is set
    """
    if power_state_flag:
        power_state = get_data(sess, oid_power_state, helper)
        power_state_summary_output, power_state_long_output = state_summary(power_state, 'Server power', server_power_state, helper, server_power_state[3])
        add_output(power_state_summary_output, power_state_long_output, helper)
def check_server_power():
    """
    Check if the server is powered on
    Skip this check, if the --noPowerState is set
    """
    if power_state_flag:
        power_state = get_data(sess, oid_power_state, helper)
        power_state_summary_output, power_state_long_output = state_summary(power_state, 'Server power', server_power_state, helper, server_power_state[3])
        add_output(power_state_summary_output, power_state_long_output, helper)
def check_satellites():
    """
    check and show the good satellites
    """
    # here we get the value for the satellites
    good_satellites = get_data(sess, oid_gps_satellites_good, helper)

    # Show the summary and add the metric and afterwards check the metric
    helper.add_summary("Good satellites: %s" % good_satellites)
    helper.add_metric(label='satellites', value=good_satellites)
예제 #12
0
def check_global_status(flag, name, oid):
    """
    check a global status
    check_global_status(True, "Global Storage", '.1.3.6.1.4.1.232.3.1.3.0')
    """
    # only check the status, if the "no" flag is not set
    if flag:
        # get the data via snmp
        myData = get_data(sess, oid, helper)
        data_summary_output, data_long_output = state_summary(myData, name, normal_state, helper)
        add_output(data_summary_output, data_long_output, helper)
def check_global_status(flag, name, oid):
    """
    check a global status
    check_global_status(True, "Global Storage", '.1.3.6.1.4.1.232.3.1.3.0')
    """
    # only check the status, if the "no" flag is not set
    if flag:
        # get the data via snmp
        myData = get_data(sess, oid, helper)
        data_summary_output, data_long_output = state_summary(myData, name, normal_state, helper)
        add_output(data_summary_output, data_long_output, helper)
def check_controller(sess):
    """
    check the status of the controller
    """
    controller_operational = get_data(sess, operational_oid, helper)
    controller_availability = get_data(sess, availability_oid, helper)
    controller_alarm = get_data(sess, alarm_oid, helper)

    # Add summary
    helper.add_summary("Controller Status")

    # Add all states to the long output
    helper.add_long_output("Controller Operational State: %s" %
                           operational_states[int(controller_operational)])
    helper.add_long_output("Controller Availability State: %s" %
                           availability_states[int(controller_availability)])
    helper.add_long_output("Controller Alarm State: %s" %
                           alarm_states[int(controller_alarm)])

    # Operational State
    if controller_operational != "1" and controller_operational != "4":
        helper.status(critical)
        helper.add_summary("Controller Operational State: %s" %
                           operational_states[int(controller_operational)])

    # Avaiability State
    if controller_availability != "3":
        helper.status(critical)
        helper.add_summary("Controller Availability State: %s" %
                           availability_states[int(controller_availability)])

    # Alarm State
    if controller_alarm == "2":
        helper.status(warning)
        helper.add_summary("Controller Alarm State: %s" %
                           alarm_states[int(controller_alarm)])
    if controller_alarm == "3" or controller_alarm == "4":
        helper.status(critical)
        helper.add_summary("Controller Alarm State: %s" %
                           alarm_states[int(controller_alarm)])
def check_gps_status():
    """
    check and show the current GPS status
    """
    gps_status_int = get_data(sess, oid_gps_mode_int, helper)

    try:
        gps_mode_string = gps_mode[gps_status_int]
    except KeyError:
        # if we receive an value, that is not in the dict
        helper.exit(summary="received an undefined value from device: " +
                    gps_status_int,
                    exit_code=unknown,
                    perfdata='')

    if gps_mode_string != "normalOperation" and gps_mode_string != "gpsSync":
        # that is a warning condition, NTP could still work without the GPS antenna
        helper.status(warning)
        helper.add_summary("GPS status: " + gps_mode_string)
def check_ntp_status():
    """
    check and show the current NTP status
    """
    ntp_status_int = get_data(sess, oid_ntp_current_state_int, helper)

    # convert the ntp_status integer value in a human readable value
    try:
        ntp_status_string = ntp_status[ntp_status_int]
    except KeyError:
        # if we receive an value, that is not in the dict
        helper.exit(summary="received an undefined value from device: " +
                    ntp_status_int,
                    exit_code=unknown,
                    perfdata='')

    # the ntp status should be synchronized (new MIB) or normalOperation (old mib)
    if ntp_status_string != "synchronized" and ntp_status_string != "normalOperationPPS":
        # that is a critical condition, because the time reference will not be reliable anymore
        helper.status(critical)
        helper.add_summary("NTP status: " + ntp_status_string)
  helper.status(ok)
  
  # shows the list of possible types if the flag is set
  if flag_list == True:
    for w,v in zip(names, descriptions):
      print w + ' = ' + v
    helper.status(unknown)
    helper.exit(summary='This is just a list and not a check!')
  
  # verify that a hostname is set
  verify_host(host, helper)
  
  # open session after validated host
  sess = netsnmp.Session(Version=version, DestHost=host, Community=community)
  
  # verify, that status(/type) parameter is not empty
  if (status == None) or (status not in names):
    helper.status(unknown)
    helper.exit(summary='Argument -t is missing or false!')
  
  # snmp gets for all oids in type-list
  ind = names.index(status)
  value = get_data(sess, basicoid+oid[ind],helper)
  
  # metric compares
  helper.add_metric(label='type', value = value, uom =' '+descriptions[ind]+' ')
  helper.check_all_metrics()
  
  # programm end
  helper.exit()
                                                                  a_helper.options.privproto, \
                                                                  a_helper.options.privpass

    host, version, community = snmpSessionBaseClass.get_common_options(
        a_helper)

    snmpSessionBaseClass.verify_host(host, a_helper)
    verify_type(a_helper.options.type, a_helper)

    snmp_session = netsnmp.Session(Version=version,
                                   DestHost=host,
                                   SecLevel=seclevel,
                                   SecName=secname,
                                   AuthProto=authproto,
                                   AuthPass=authpass,
                                   PrivProto=privproto,
                                   PrivPass=privpass,
                                   Community=community)

    # The default return value should be always OK
    a_helper.status(pynag.Plugins.ok)

    apc_check = apc_check_configs[a_helper.options.type]["check"]
    apc_oid = apc_check_configs[a_helper.options.type]["oid"]
    a_snmp_value = snmpSessionBaseClass.get_data(snmp_session, apc_oid,
                                                 a_helper)
    apc_check(snmp_session, a_helper, a_snmp_value)

    # Print out plugin information and exit nagios-style
    a_helper.exit()
    "RF Switch 1": "iso.3.6.1.4.1.20712.2.1.3.1.2.11",
    "RF Switch 2": "iso.3.6.1.4.1.20712.2.1.3.1.2.12"
}

status = {"0": "No Fault", "1": "Fault", "2": "N/A", "3": "Pos1", "4": "Pos2"}

if __name__ == "__main__":

    # verify that a hostname is set
    verify_host(host, helper)

    # The default return value should be always OK
    helper.status(ok)

    sess = netsnmp.Session(Version=version, DestHost=host, Community=community)

    # here we check the status
    for name in sorted(oids):

        # get the snmp values
        value = get_data(sess, oids[name], helper)

        helper.add_summary("%s: %s" % (name, status[value]))

        # if the value is 1 / Fault the status is set to critical
        if value == "1":
            helper.status(critical)

    # Print out plugin information and exit nagios-style
    helper.exit()
    "2" : "Alarmed"
    }

if __name__ == "__main__":

    # verify that a hostname is set
    verify_host(host, helper)

    # The default return value should be always OK
    helper.status(ok)

    sess = netsnmp.Session(Version=version, DestHost=host, Community=community)

    # get the values
    if unit == "1":
        value = get_data(sess, unit1_oid, helper)
    elif unit == "2":
        value = get_data(sess, unit2_oid, helper)
    else:
        helper.exit(summary="Wrong unit specified", exit_code=unknown, perfdata='')


    # add the summary
    helper.add_summary("Unit status is: %s" % (status[value]))

    if value == "2":
        helper.status(critical)

    # Print out plugin information and exit nagios-style
    helper.exit()
예제 #21
0
def check_partition():
    """
    check the defined partition
    """

    all_index = walk_data(sess, oid_hrStorageIndex, helper)[0]
    all_descriptions = walk_data(sess, oid_hrStorageDescr, helper)[0]
    # we need the sucess flag for the error handling (partition found or not found)
    sucess = False

    # here we zip all index and descriptions to have a list like
    # [('Physical memory', '1'), ('Virtual memory', '3'), ('/', '32'), ('/proc/xen', '33')]
    zipped = zip(all_index, all_descriptions)

    for partition in zipped:
        index = partition[0]
        description = partition[1]

        if partition_found(disk, description):
            # we found the partition
            sucess = True

            # receive all values we need
            unit = float(
                get_data(sess, oid_hrStorageAllocationUnits + "." + index,
                         helper))
            size = float(
                get_data(sess, oid_hrStorageSize + "." + index, helper))
            used = float(
                get_data(sess, oid_hrStorageUsed + "." + index, helper))

            if size == 0 or used == 0:
                # if the host return "0" as used or size, then we have a problem with the calculation (devision by zero)
                helper.exit(
                    summary=
                    "Received value 0 as StorageSize or StorageUsed: calculation error",
                    exit_code=unknown,
                    perfdata='')

            # calculate the real size (size*unit) and convert the results to the target unit the user wants to see
            used_result = convert_to_XX(calculate_real_size(used), unit,
                                        targetunit)
            size_result = convert_to_XX(calculate_real_size(size), unit,
                                        targetunit)

            # calculation of the used percentage
            percent_used = used_result / size_result * 100

            # we need a string and want only two decimals
            used_string = str(float("{0:.2f}".format(used_result)))
            size_string = str(float("{0:.2f}".format(size_result)))
            percent_string = str(float("{0:.2f}".format(percent_used)))

            if percent_used < 0 or percent_used > 100:
                # just a validation that percent_used is not smaller then 0% or lager then 100%
                helper.exit(
                    summary="Calculation error - second counter overrun?",
                    exit_code=unknown,
                    perfdata='')

            # show the summary
            helper.add_summary("%s%% used (%s%s of %s%s) at '%s'" %
                               (percent_string, used_string, targetunit,
                                size_string, targetunit, description))
            # add the metric in percent.
            helper.add_metric(label='percent used',
                              value=percent_string,
                              min="0",
                              max="100",
                              uom="%")

    else:
        if not sucess:
            # if the partition was not found in the data output, we return an error
            helper.exit(summary="Partition '%s' not found" % disk,
                        exit_code=unknown,
                        perfdata='')
def check_sensor(sess):
    """
    check the status of the specified sensor
    """

    sensor_name = get_data(sess, oid_sensor_name, helper)
    sensor_state = get_data(sess, oid_sensor_state, helper)
    sensor_state_string = states[int(sensor_state)]
    sensor_unit = ""  # if it's a onOff Sensor or something like that, we need an empty string for the summary
    sensor_unit_string = ""
    sensor_value = ""
    sensor_digit = ""
    real_sensor_value = ""
    sensor_type = get_data(sess, oid_sensor_type, helper)
    sensor_warning_upper = ""
    sensor_critical_upper = ""
    sensor_warning_lower = ""
    sensor_critical_lower = ""

    if int(sensor_type) not in [14, 16, 17, 18, 19, 20]:
        # for all sensors except these, we want to calculate the real value and show the metric.
        # 14: onOff
        # 16: vibration
        # 17: waterDetection
        # 18: smokeDetection
        # 19: binary
        # 20: contact
        sensor_unit = int(get_data(sess, oid_sensor_unit, helper))
        sensor_unit_string = units[int(sensor_unit)]
        sensor_digit = get_data(sess, oid_sensor_digit, helper)
        sensor_warning_upper = get_data(sess, oid_sensor_warning_upper, helper)
        sensor_critical_upper = get_data(sess, oid_sensor_critical_upper,
                                         helper)
        sensor_warning_lower = get_data(sess, oid_sensor_warning_lower, helper)
        sensor_critical_lower = get_data(sess, oid_sensor_critical_lower,
                                         helper)
        sensor_value = int(get_data(sess, oid_sensor_value, helper))
        real_sensor_value = real_value(sensor_value, sensor_digit)
        real_sensor_warning_upper = real_value(sensor_warning_upper,
                                               sensor_digit)
        real_sensor_critical_upper = real_value(sensor_critical_upper,
                                                sensor_digit)
        real_sensor_warning_lower = real_value(sensor_warning_lower,
                                               sensor_digit)
        real_sensor_critical_lower = real_value(sensor_critical_lower,
                                                sensor_digit)
        # metrics are only possible for these sensors
        helper.add_metric(sensor_name, real_sensor_value, real_sensor_warning_lower +\
                          ":" + real_sensor_warning_upper, real_sensor_critical_lower +\
                          ":" + real_sensor_critical_upper, "", "", sensor_unit_string)

    # "OK" state
    if sensor_state_string in [
            "closed", "normal", "on", "notDetected", "ok", "yes", "one", "two",
            "inSync"
    ]:
        helper.status(ok)

    # "WARNING" state
    elif sensor_state_string in [
            "open", "belowLowerWarning", "aboveUpperWarning", "marginal",
            "standby"
    ]:
        helper.status(warning)

    # "CRITICAL" state
    elif sensor_state_string in [
            "belowLowerCritical", "aboveUpperCritical", "off", "detected",
            "alarmed", "fail", "no", "outOfSync"
    ]:
        helper.status(critical)

    # "UNKOWN" state
    elif sensor_state_string in ["unavailable"]:
        helper.status(unknown)

    # received an undefined state
    else:
        helper.exit(summary="Something went wrong - received undefined state",
                    exit_code=unknown,
                    perfdata='')

    # summary is shown for all sensors
    helper.add_summary("Sensor %s - '%s' %s%s is: %s" %
                       (number, sensor_name, real_sensor_value,
                        sensor_unit_string, sensor_state_string))
예제 #23
0
                    voltage_probe_reading_data[x])
    #erase the last '.'for a prettier summary output
    voltage_probe_summary_output = voltage_probe_summary_output[:-2]
    return voltage_probe_summary_output, voltage_probe_long_output


if __name__ == '__main__':
    # verify that a hostname is set
    verify_host(host, helper)

    # The default return value should be always OK
    helper.status(ok)

    sess = netsnmp.Session(Version=version, DestHost=host, Community=community)

    user_assigned_name_data = get_data(sess, oid_user_assigned_name, helper)
    product_type_data = get_data(sess, oid_product_type, helper)
    service_tag_data = get_data(sess, oid_service_tag, helper)

    helper.add_summary(
        'User assigned name: %s - Typ: %s - Service tag: %s' %
        (user_assigned_name_data, product_type_data, service_tag_data))

    global_system_data = get_data(sess, oid_global_system, helper)
    system_lcd_data = get_data(sess, oid_system_lcd, helper)
    global_storage_data = get_data(sess, oid_global_storage, helper)
    system_power_data = get_data(sess, oid_system_power, helper)

    global_system_summary, global_system_long = state_summary(
        global_system_data, 'Global System', normal_state, helper)
    system_lcd_summary, system_lcd_long = state_summary(
예제 #24
0
    parameter_list = [host, version, community, helper]

    # The default return value should be always OK
    helper.status(ok)

    # verify that a hostname is set
    verify_host(host, helper)

    sess = netsnmp.Session(Version=version, DestHost=host, Community=community)

    # If the --scan option is set, we show all components and end the script
    if scan:
        scan_ilo()

    # Show always the product name and the serial number in the summary
    product_name = get_data(sess, oid_product_name, helper)
    serial_number = get_data(sess, oid_serial_numb, helper)
    helper.add_summary('%s - Serial number:%s' % (product_name, serial_number))

    # Verify that there is an input for the amount of components
    if input_phy_drv == '' or input_phy_drv is None:
        helper.exit(
            summary="Amount of physical drives must be specified (--drives)",
            exit_code=unknown,
            perfdata='')
    if input_pwr_sply == '' or input_pwr_sply is None:
        helper.exit(
            summary="Amount of power supplies must be specified (--ps)",
            exit_code=unknown,
            perfdata='')
    if input_fan == '' or input_fan is None:
    # verify that a hostname is set
    verify_host(host, helper)
    
    # verify that seclevel is correctly used, otherwise there will be an exception
    verify_seclevel(seclevel, helper)

    sess = netsnmp.Session(Version=version, DestHost=host, SecLevel=seclevel,  SecName=secname, AuthProto=authproto,
                           AuthPass=authpass, PrivProto=privproto, PrivPass=privpass, Community=community)
    
    # If the --scan option is set, we show all components and end the script
    if scan:
        scan_ilo()
    
    # Show always the product name and the serial number in the summary
    product_name = get_data(sess, oid_product_name, helper)
    serial_number = get_data(sess, oid_serial_numb, helper)
    helper.add_summary('%s - Serial number:%s' % (product_name, serial_number))
    
    # Verify that there is an input for the amount of components
    if input_phy_drv == '' or input_phy_drv is None:
        helper.exit(summary="Amount of physical drives must be specified (--drives)", exit_code=unknown, perfdata='')
    if input_pwr_sply == '' or input_pwr_sply is None:
        helper.exit(summary="Amount of power supplies must be specified (--ps)", exit_code=unknown, perfdata='')
    if input_fan == '' or input_fan is None:
        helper.exit(summary="Amount of fans must be specified (--fan)", exit_code=unknown, perfdata='')

    # Check the global status
    check_global_status(storage_flag, 'Global storage', oid_storage)
    check_global_status(system_flag,'Global system',oid_system)
    check_global_status(power_supply_flag,'Global power supply',oid_glob_power_supply)
예제 #26
0

if __name__ == "__main__":

    # verify that a hostname is set
    verify_host(host, helper)

    # The default return value is unknown
    helper.status(ok)

    sess = netsnmp.Session(Version=version, DestHost=host, Community=community)

    #query the data depending on the service
    try:
        oid = services[service]
        value = get_data(sess, oid, helper)
    except KeyError:
        helper.exit(summary="Wrong service specified", exit_code=unknown, perfdata='')

    # if one of the handover values drop to 0, show a warning.
    if service in ["HandoverConnectionsIn", "HandoverConnectionsOut"]:
        helper.add_summary("Currently %s %s" % (value, service))
        if int(value) == 0:
            helper.status(warning)
        else:
            helper.status(ok)
    
    else:
        # add the summary
        helper.add_summary("%s status is: %s" % (service, value))
                                                              helper.options.authpass, \
                                                              helper.options.privproto, \
                                                              helper.options.privpass

if __name__ == "__main__":
    # verify that a hostname is set
    verify_host(host, helper)

    # The default return value should be always OK
    helper.status(ok)

    sess = netsnmp.Session(Version=version, DestHost=host, SecLevel=seclevel, SecName=secname, AuthProto=authproto,
                           AuthPass=authpass, PrivProto=privproto, PrivPass=privpass, Community=community)

    # get the remote time
    remote_time = get_data(sess, '.1.3.6.1.2.1.25.1.2.0', helper)
    # get the description (operating system)
    descr = get_data(sess, '.1.3.6.1.2.1.1.1.0', helper)

    # check if we are on a windows system
    windows = False
    if str(descr).find('Windows') != -1:
        windows = True

    # Extracting the remote time data from the OID
    # Value can be either 8 or 11 octets long
    # The first try is for the length of eleven, the second for eight octets
    try:
        # unpack returns: year(first octet)|year(second octet)|month|day|hour|minute|second|deci-seconds|direction from UTC|hours from UTC|minutes from UTC
        # e.g.: 07|224|04|09|13|04|43|00|+|02|00
        # you have to convert the first two octets to get the year e.g.: 0x07|0xE0 => 0x07=7, 0xE0=224 => 07*256=1792, 1762+224=2016
    for w,v in zip(names, descriptions):
      print w + ' = ' + v
    helper.status(unknown)
    helper.exit(summary='This is just a list and not a check!')
  
  # verify that a hostname is set
  verify_host(host, helper)
  
  # open session after validated host
  sess = netsnmp.Session(Version=version, DestHost=host, Community=community)
  
  # verify, that status(/type) parameter is not empty
  if (status == None) or (status not in names):
    helper.status(unknown)
    helper.exit(summary='Argument -t is missing or false!')
  
  # snmp gets for all oids in type-list
  ind = names.index(status)
  value = get_data(sess, oids[ind],helper)
  
  if names.index(status) == 0:
    value = str(datetime.timedelta(seconds=int(value)))
    helper.exit(summary='Uptime = %s'%value)
  
  # metric compares
  helper.add_metric(label='type', value = value, uom =' '+units[ind]+' ')
  helper.check_all_metrics()
  
  # programm end
  helper.exit()
    "1" : "Fault",
    "2" : "N/A",
    "3" : "Pos1",
    "4" : "Pos2"
    }

if __name__ == "__main__":

    # verify that a hostname is set
    verify_host(host, helper)

    # The default return value should be always OK
    helper.status(ok)

    sess = netsnmp.Session(Version=version, DestHost=host, Community=community)

    # here we check the status
    for name in sorted(oids):
        
        # get the snmp values
        value = get_data(sess, oids[name], helper)

        helper.add_summary("%s: %s" % (name, status[value]))
        
        # if the value is 1 / Fault the status is set to critical
        if value == "1":
            helper.status(critical)

    # Print out plugin information and exit nagios-style
    helper.exit()
예제 #30
0
#Get the options
host, version, community    = get_common_options(helper)
o_tzoff                     = helper.options.tzoffset
use_local                   = helper.options.time_flag

if __name__ == "__main__":
    # verify that a hostname is set
    verify_host(host, helper)    
    
    #The default return value should be always OK
    helper.status(ok)
    
    sess = netsnmp.Session(Version=version, DestHost=host, Community=community)
    
    # get the remote time
    remote_time                 = get_data(sess, '.1.3.6.1.2.1.25.1.2.0', helper)
    # get the description (operating system)
    descr                       = get_data(sess, '.1.3.6.1.2.1.1.1.0', helper)
    
    # check if we are on a windows system
    windows = False
    if str(descr).find('Windows') != -1:
        windows = True
    
    #Extracting the remote time data from the OID
    #Value can be either 8 or 11 octets long 
    #The first try is for the length of eleven, the second for eight octets
    try:
        #unpack returns: year(first octet)|year(second octet)|month|day|hour|minute|second|deci-seconds|direction from UTC|hours from UTC|minutes from UTC 
        #e.g.: 07|224|04|09|13|04|43|00|+|02|00 
        #you have to convert the first two octets to get the year e.g.: 0x07|0xE0 => 0x07=7, 0xE0=224 => 07*256=1792, 1762+224=2016
예제 #31
0
    a_helper.parse_arguments()

    return a_helper


if __name__ == "__main__":
    a_helper = setup_plugin_helper()

    snmpSessionBaseClass.verify_host(a_helper.options.hostname, a_helper)
    verify_type(a_helper.options.type, a_helper)

    snmp_session = netsnmp.Session(Version=1,
                                   DestHost=a_helper.options.hostname,
                                   Community=a_helper.options.community)

    # The default return value should be always OK
    a_helper.status(pynag.Plugins.ok)

    eaton_check = eaton_check_configs[a_helper.options.type]["check"]
    eaton_oid = eaton_check_configs[a_helper.options.type]["oid"]
    allow_empty = eaton_check_configs[a_helper.options.type].get(
        "allow_snmp_empty", False)

    a_snmp_value = snmpSessionBaseClass.get_data(snmp_session, eaton_oid,
                                                 a_helper, allow_empty)
    eaton_check(snmp_session, a_helper, a_snmp_value)

    ## Print out plugin information and exit nagios-style
    a_helper.exit()
    "2" : "Alarmed"
    }

if __name__ == "__main__":

    # verify that a hostname is set
    verify_host(host, helper)

    # The default return value should be always OK
    helper.status(ok)

    sess = netsnmp.Session(Version=version, DestHost=host, Community=community)

    # get the values
    if unit == "1":
        value = get_data(sess, unit1_oid, helper)
    elif unit == "2":
        value = get_data(sess, unit2_oid, helper)
    else:
        helper.exit(summary="Wrong unit specified", exit_code=unknown, perfdata='')


    # add the summary
    helper.add_summary("Unit status is: %s" % (status[value]))

    if value == "2":
        helper.status(critical)

    # Print out plugin information and exit nagios-style
    helper.exit()
def check_gps_position():
    """
    just print the curret GPS position
    """
    gps_position = get_data(sess, oid_gps_position, helper)
    helper.add_summary(gps_position)
    # shows the list of possible types if the flag is set
    if flag_list == True:
        for w, v in zip(names, descriptions):
            print w + ' = ' + v
        helper.status(unknown)
        helper.exit(summary='This is just a list and not a check!')

    # verify that a hostname is set
    verify_host(host, helper)

    # open session after validated host
    sess = netsnmp.Session(Version=version, DestHost=host, Community=community)

    # verify, that status(/type) parameter is not empty
    if (status == None) or (status not in names):
        helper.status(unknown)
        helper.exit(summary='Argument -t is missing or false!')

    # snmp gets for all oids in type-list
    ind = names.index(status)
    value = get_data(sess, basicoid + oid[ind], helper)

    # metric compares
    helper.add_metric(label='type',
                      value=value,
                      uom=' ' + descriptions[ind] + ' ')
    helper.check_all_metrics()

    # programm end
    helper.exit()

if __name__ == "__main__":
    a_helper = setup_plugin_helper()

    secname, seclevel, authproto, authpass, privproto, privpass = a_helper.options.secname, \
                                                                  a_helper.options.seclevel, \
                                                                  a_helper.options.authproto, \
                                                                  a_helper.options.authpass, \
                                                                  a_helper.options.privproto, \
                                                                  a_helper.options.privpass

    host, version, community = snmpSessionBaseClass.get_common_options(a_helper)

    snmpSessionBaseClass.verify_host(host, a_helper)
    verify_type(a_helper.options.type, a_helper)

    snmp_session = netsnmp.Session(Version=version, DestHost=host, SecLevel=seclevel, SecName=secname, AuthProto=authproto,
                              AuthPass=authpass, PrivProto=privproto, PrivPass=privpass, Community=community)

    # The default return value should be always OK
    a_helper.status(pynag.Plugins.ok)

    apc_check = apc_check_configs[a_helper.options.type]["check"]
    apc_oid = apc_check_configs[a_helper.options.type]["oid"]
    a_snmp_value = snmpSessionBaseClass.get_data(snmp_session, apc_oid, a_helper)
    apc_check(snmp_session, a_helper, a_snmp_value)

    # Print out plugin information and exit nagios-style
    a_helper.exit()