def scan_ilo():
    helper.status(critical)
    ps_data = walk_data(sess, oid_ps, helper)[0]
    fan_data = walk_data(sess, oid_fan, helper)[0]
    
    # we don't receive a result, if no physical drives are available.
    phy_drv_status = attempt_walk_data(sess, oid_phy_drv_status)[0]
    
    helper.add_long_output('Available devices:')
    helper.add_long_output('')

    # show the physical drives
    if phy_drv_status:
        for x, data in enumerate(phy_drv_status, 1):
            helper.add_long_output('Physical drive %d: %s' % (x, phy_drv_state[int(data)]))
    else:
        helper.add_long_output("No physical drives detected")
    # add a empty line after the pyhsical drives
    helper.add_long_output('')

    # show the power supplies
    for x, data in enumerate(ps_data, 1):
        helper.add_long_output('Power supply %d: %s'  % (x, normal_state[int(data)]))
    helper.add_long_output('')

    # show the fans
    for x, data in enumerate(fan_data, 1):
        helper.add_long_output('Fan %d: %s'  % (x, normal_state[int(data)]))
    
    helper.exit(exit_code=ok, perfdata='')
Esempio n. 2
0
def check_temperature_sensors():
    """
    Check all temperature sensors of the server
    All sensors with the value or threshold is -99 or 0 are ignored
    """
    # walk all temperature sensor values and thresholds
    env_temp = walk_data(sess, oid_env_temp, helper)[0]
    env_temp_thresh = walk_data(sess, oid_env_temp_thres, helper)[0]
    env_temp_zipped = zip(env_temp, env_temp_thresh)

    for x, data in enumerate(env_temp_zipped, 1):
        # skip the check if -99 or 0 is in the value or threshold, because these data we can not use
        if '-99' not in data and '0' not in data:
            #check if the value is over the treshold
            if int(data[0]) > int(data[1]):
                helper.add_summary(
                    'Temperature at sensor %d above threshold (%s / %s)' %
                    (x, data[0], data[1]))
                helper.status(critical)
            # always add the sensor to the output
            helper.add_long_output(
                'Temperature %d: %s Celsius (threshold: %s Celsius)' %
                (x, data[0], data[1]))
            # for the first sensor (envirnoment temperature, we add performance data)
            if x == 1:
                helper.add_metric("Environment Temperature", data[0], '',
                                  ":" + data[1], "", "", "Celsius")
Esempio n. 3
0
def check_sensors():
    """
    collect and check all available sensors
    """

    all_sensors = walk_data(sess, oid_description, helper)[0]
    all_status = walk_data(sess, oid_status, helper)[0]

    # here we zip all index and descriptions to have a list like
    # [('Fan Sensor', '2'), ('Power Supply Sensor', '4')]
    # we are doomed if the lists do not have the same length ...  but that should never happen ... hopefully
    zipped = zip(all_sensors, all_status)

    for sensor in zipped:
        description = sensor[0]
        status = sensor[1]
        # translate the value to human readable
        try:
            status_string = senor_status_table[status]
        except KeyError:
            # if we receive an invalid value, we don't want to crash...
            helper.exit(summary="received an undefined value from device: " +
                        status,
                        exit_code=unknown,
                        perfdata='')

        # for each sensor the summary is added like: Fan Sensor: good
        helper.add_summary("%s: %s" % (description, status_string))

        # set the status
        if status == "2":
            helper.status(critical)
        if status == "3":
            helper.status(warning)
def check_sensors():
    """
    collect and check all available sensors
    """

    all_sensors = walk_data(sess, oid_description, helper)[0]
    all_status = walk_data(sess, oid_status, helper)[0]

    # here we zip all index and descriptions to have a list like
    # [('Fan Sensor', '2'), ('Power Supply Sensor', '4')]
    # we are doomed if the lists do not have the same length ...  but that should never happen ... hopefully
    zipped = zip(all_sensors, all_status)

    for sensor in zipped:
        description = sensor[0]
        status = sensor[1]
        # translate the value to human readable
        try:
            status_string = senor_status_table[status]
        except KeyError:
            # if we receive an invalid value, we don't want to crash... 
            helper.exit(summary="received an undefined value from device: " + status, exit_code=unknown, perfdata='')

        # for each sensor the summary is added like: Fan Sensor: good
        helper.add_summary("%s: %s" % (description, status_string))

        # set the status
        if status == "2":
            helper.status(critical)
        if status == "3":
            helper.status(warning)
def check_tcp(helper, host, port, warning_param, critical_param, session):
    """
    the check logic for check TCP ports
    """

    # from tcpConnState from TCP-MIB
    tcp_translate = {
        "1": "closed",
        "2": "listen",
        "3": "synSent",
        "4": "synReceived",
        "5": "established",
        "6": "finWait1",
        "7": "finWait2",
        "8": "closeWait",
        "9": "lastAck",
        "10": "closing",
        "11": "timeWait",
        "12": "deleteTCB"
    }

    # collect all open local ports
    open_ports = walk_data(
        session, '.1.3.6.1.2.1.6.13.1.3',
        helper)[0]  #tcpConnLocalPort from TCP-MIB (deprecated)
    # collect all status information about the open ports
    port_status = walk_data(session, '.1.3.6.1.2.1.6.13.1.1',
                            helper)[0]  #tcpConnState from TCP-MIB (deprecated)
    # make a dict out of the two lists
    port_and_status = dict(zip(open_ports, port_status))

    # here we show all open TCP ports and it's status
    if scan:
        print "All open TCP ports: " + host
        for port in open_ports:
            tcp_status = port_and_status[port]
            tcp_status = tcp_translate[tcp_status]
            print "TCP: \t" + port + "\t Status: \t" + tcp_status
        quit()

    #here we have the real check logic for TCP ports
    if port in open_ports:
        # if the port is available in the list of open_ports, then extract the status
        tcp_status = port_and_status[port]
        # translate the status from the integer value to a human readable string
        tcp_status = tcp_translate[tcp_status]

        # now let's set the status according to the warning / critical "threshold" parameter
        if tcp_status in warning_param:
            helper.status(warning)
        elif tcp_status in critical_param:
            helper.status(critical)
        else:
            helper.status(ok)
    else:
        # if there is no value in the list => the port is closed for sure
        tcp_status = "CLOSED"
        helper.status(critical)

    return ("Current status for TCP port " + port + " is: " + tcp_status)
Esempio n. 6
0
def scan_ilo():
    helper.status(critical)
    ps_data = walk_data(sess, oid_ps, helper)[0]
    fan_data = walk_data(sess, oid_fan, helper)[0]

    # we don't receive a result, if no physical drives are available.
    phy_drv_status = attempt_walk_data(sess, oid_phy_drv_status)[0]

    helper.add_long_output('Available devices:')
    helper.add_long_output('')

    # show the physical drives
    if phy_drv_status:
        for x, data in enumerate(phy_drv_status, 1):
            helper.add_long_output('Physical drive %d: %s' %
                                   (x, phy_drv_state[int(data)]))
    else:
        helper.add_long_output("No physical drives detected")
    # add a empty line after the pyhsical drives
    helper.add_long_output('')

    # show the power supplies
    for x, data in enumerate(ps_data, 1):
        helper.add_long_output('Power supply %d: %s' %
                               (x, normal_state[int(data)]))
    helper.add_long_output('')

    # show the fans
    for x, data in enumerate(fan_data, 1):
        helper.add_long_output('Fan %d: %s' % (x, normal_state[int(data)]))

    helper.exit(exit_code=ok, perfdata='')
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='')
Esempio n. 8
0
def test_walk_data(capsys):
    """
    test of the walk_data function
    """
    #run a walk on a not existing host
    with pytest.raises(SystemExit):
        assert snmpSessionBaseClass.walk_data(failSession, '.1', helper)
    out, err = capsys.readouterr()
    assert 'Unknown - snmpwalk 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.walk_data(
        session, '.1.3.6.1.2.1.25.1.1',
        helper)[0][0][:-3] == get_system_uptime()[:-3]
def check_phy_drv(temp_drive_flag, input_phy_drv):
    physical_drive_status = walk_data(sess, oid_phy_drv_status, helper)[0]
    physical_drive_smart = walk_data(sess, oid_phy_drv_smrt, helper)[0]
    physical_drive_temp = walk_data(sess, oid_phy_drv_temp, helper)[0]
    physical_drive_temp_thres = walk_data(sess, oid_phy_drv_temp_thres, helper)[0]
    phy_drv_count_ok = 0
    summary_output = ''
    long_output = ''
    
    for x, data in enumerate(physical_drive_status, 0):
        if phy_drv_state[int(physical_drive_status[x])] == 'ok' and phy_drv_smrt_state[int(physical_drive_smart[x])] == 'ok':
            # check how many drives in OK state we find
            phy_drv_count_ok += 1
        else:
            # status is not ok
            helper.status(critical)
            summary_output += ('Physical drive %d status: %s ' % (x+1, phy_drv_state[int(physical_drive_status[x])]))
            summary_output += ('Physical drive %d smart status: %s ' % (x+1, phy_drv_smrt_state[int(physical_drive_smart[x])]))
        
        # we always want to show the drive status in the long output, independend from the status
        long_output += ('Physical drive %d status: %s\n' % (x+1, phy_drv_state[int(physical_drive_status[x])]))
        long_output += ('Physical drive %d smart status: %s\n' % (x+1, phy_drv_state[int(physical_drive_smart[x])]))
    
        # check of the harddrive temperatures
        if temp_drive_flag:
            # only evaluate the temperatures if temp_drive_flag is not set (--noDriveTemp). We need that for our 15k SAS drives.            
            if int(physical_drive_temp[x]) != -1:
                # OID returns -1 if the drive temperature (threshold) cannot be calculated or if the controller does not support reporting drive temperature threshold
                if int(physical_drive_temp_thres[x]) != -1:
                    if int(physical_drive_temp[x]) > int(physical_drive_temp_thres[x]):
                        summary_output += ('Physical drive %d temperature above threshold (%s / %s) ' % (x+1, physical_drive_temp[x], physical_drive_temp_thres[x]))
                        helper.status(critical)
                    long_output += ('Physical drive %d temperature: %s Celsius (threshold: %s Celsius)\n' % (x+1, physical_drive_temp[x], physical_drive_temp_thres[x]))
                else:
                    long_output += ('Physical drive %d temperature: %s Celsius (no threshold given)\n' % (x+1, physical_drive_temp[x]))
            
    # if the count of the found OK drives does not match the amount of configured drives (--drives parameter)
    if int(phy_drv_count_ok) != int(input_phy_drv):
        summary_output += ('%s physical drive(s) expected - %s physical drive(s) in ok state! ' % (input_phy_drv, phy_drv_count_ok))
        helper.status(critical)
    
    # Check Logical drive
    logical_drive = walk_data(sess, oid_log_drv, helper)[0]

    for x, data in enumerate(logical_drive, 1):
        log_drv_summary_output, log_drv_long_output = state_summary(data, 'Logical drive %d' % x, log_drv_state, helper)
        summary_output += log_drv_summary_output
        long_output += log_drv_long_output
    return (summary_output, long_output)
def check_accesspoints(sess):
    """
    check the status of all connected access points
    """
    ap_names = walk_data(sess, name_ap_oid, helper)[0]
    ap_operationals = walk_data(sess, operational_ap_oid, helper)[0]
    ap_availabilitys = walk_data(sess, availability_ap_oid, helper)[0]
    ap_alarms = walk_data(sess, alarm_ap_oid, helper)[0]
    #ap_ip                = walk_data(sess, ip_ap_oid, helper) # no result

    helper.add_summary("Access Points Status")

    for x in range(len(ap_names)):
        ap_name = ap_names[x]
        ap_operational = ap_operationals[x]
        ap_availability = ap_availabilitys[x]
        ap_alarm = ap_alarms[x]

        # Add all states to the long output
        helper.add_long_output(
            "%s - Operational: %s - Availabilty: %s - Alarm: %s" %
            (ap_name, operational_states[int(ap_operational)],
             availability_states[int(ap_availability)],
             alarm_states[int(ap_alarm)]))

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

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

        # Alarm State
        if ap_alarm == "2":
            helper.status(warning)
            helper.add_summary("%s Controller Alarm State: %s" %
                               (ap_name, alarm_states[int(ap_alarm)]))

        if ap_alarm == "3" or ap_alarm == "4":
            helper.status(critical)
            helper.add_summary("%s Controller Alarm State: %s" %
                               (ap_name, alarm_states[int(ap_alarm)]))
Esempio n. 11
0
def check_phy_drv(temp_drive_flag, input_phy_drv):
    physical_drive_status = walk_data(sess, oid_phy_drv_status, helper)[0]
    physical_drive_smart = walk_data(sess, oid_phy_drv_smrt, helper)[0]
    physical_drive_temp = walk_data(sess, oid_phy_drv_temp, helper)[0]
    physical_drive_temp_thres = walk_data(sess, oid_phy_drv_temp_thres, helper)[0]
    phy_drv_count_ok = 0
    summary_output = ''
    long_output = ''
    
    for x, data in enumerate(physical_drive_status, 0):
        if phy_drv_state[int(physical_drive_status[x])] == 'ok' and phy_drv_smrt_state[int(physical_drive_smart[x])] == 'ok':
            # check how many drives in OK state we find
            phy_drv_count_ok += 1
        else:
            # status is not ok
            helper.status(critical)
            summary_output += ('Physical drive %d status: %s ' % (x+1, phy_drv_state[int(physical_drive_status[x])]))
            summary_output += ('Physical drive %d smart status: %s ' % (x+1, phy_drv_smrt_state[int(physical_drive_smart[x])]))
        
        # we always want to show the drive status in the long output, independend from the status
        long_output += ('Physical drive %d status: %s\n' % (x+1, phy_drv_state[int(physical_drive_status[x])]))
        long_output += ('Physical drive %d smart status: %s\n' % (x+1, phy_drv_state[int(physical_drive_smart[x])]))
    
        # check of the harddrive temperatures
        if temp_drive_flag:
            # only evaluate the temperatures if temp_drive_flag is not set (--noDriveTemp). We need that for our 15k SAS drives.            
            if int(physical_drive_temp[x]) != -1:
                # OID returns -1 if the drive temperature (threshold) cannot be calculated or if the controller does not support reporting drive temperature threshold
                if int(physical_drive_temp_thres[x]) != -1:
                    if int(physical_drive_temp[x]) > int(physical_drive_temp_thres[x]):
                        summary_output += ('Physical drive %d temperature above threshold (%s / %s) ' % (x+1, physical_drive_temp[x], physical_drive_temp_thres[x]))
                        helper.status(critical)
                    long_output += ('Physical drive %d temperature: %s Celsius (threshold: %s Celsius)\n' % (x+1, physical_drive_temp[x], physical_drive_temp_thres[x]))
                else:
                    long_output += ('Physical drive %d temperature: %s Celsius (no threshold given)\n' % (x+1, physical_drive_temp[x]))
            
    # if the count of the found OK drives does not match the amount of configured drives (--drives parameter)
    if int(phy_drv_count_ok) != int(input_phy_drv):
        summary_output += ('%s physical drive(s) expected - %s physical drive(s) in ok state! ' % (input_phy_drv, phy_drv_count_ok))
        helper.status(critical)
    
    # Check Logical drive
    logical_drive = walk_data(sess, oid_log_drv, helper)[0]

    for x, data in enumerate(logical_drive, 1):
        log_drv_summary_output, log_drv_long_output = state_summary(data, 'Logical drive %d' % x, log_drv_state, helper)
        summary_output += log_drv_summary_output
        long_output += log_drv_long_output
    return (summary_output, long_output)
Esempio n. 12
0
def check_ps():
    """
    Check if the power supplies are ok, and we have the configured amount
    The check is skipped if --ps=0
    """
    if int(input_pwr_sply) != 0:
        ps_data = walk_data(sess, oid_ps, helper)[0]
        ps_ok_count = 0

        for x, state in enumerate(ps_data, 1):
            # human readable status
            hr_status = normal_state[int(state)]
            if hr_status != "ok":
                # if the power supply is ok, we will set a critical status and add it to the summary
                helper.add_summary('Power supply status %s: %s' %
                                   (x, hr_status))
                helper.status(critical)
            else:
                # if everything is ok, we increase the ps_ok_count
                ps_ok_count += 1

            # we always want to see the status in the long output
            helper.add_long_output('Power supply status %s: %s' %
                                   (x, hr_status))
        helper.add_long_output('')

        if int(input_pwr_sply) != ps_ok_count:
            # if the confiugred power supplies and power supplies in ok state are different
            helper.add_summary(
                '%s power supplies expected - %s power supplies ok ' %
                (input_pwr_sply, ps_ok_count))
            helper.status(critical)
Esempio n. 13
0
def check_fan(input_fan):
    """
    check the fans
    """
    # get a list of all fans
    fan_data = walk_data(sess, oid_fan, helper)[0]

    fan_count = 0
    summary_output = ''
    long_output = ''

    for x, fan in enumerate(fan_data, 1):
        fan = int(fan)
        if normal_state[fan] == 'ok':
            # if the fan is ok, we increase the fan_count varaible
            fan_count += 1
        # we always want to the the status in the long output
        long_output += 'Fan %d: %s.\n' % (x, normal_state[fan])

    # check we have the correct amount ok fans in OK state, otherwise set status to critical and print the fan in the summary
    if int(fan_count) != int(input_fan):
        summary_output += '%s fan(s) expected - %s fan(s) ok. ' % (input_fan,
                                                                   fan_count)
        helper.status(critical)
    return (summary_output, long_output)
def check_ps():    
    """
    Check if the power supplies are ok, and we have the configured amount
    The check is skipped if --ps=0
    """
    if int(input_pwr_sply) != 0:        
        ps_data = walk_data(sess, oid_ps, helper)[0]
        ps_ok_count = 0
        
        for x, state in enumerate(ps_data, 1):
            # human readable status
            hr_status = normal_state[int(state)]
            if  hr_status != "ok":
                # if the power supply is ok, we will set a critical status and add it to the summary
                helper.add_summary('Power supply status %s: %s' % (x, hr_status))
                helper.status(critical)
            else:
                # if everything is ok, we increase the ps_ok_count
                ps_ok_count += 1
            
            # we always want to see the status in the long output
            helper.add_long_output('Power supply status %s: %s' % (x, hr_status))
        helper.add_long_output('')

        if int(input_pwr_sply) != ps_ok_count:
            # if the confiugred power supplies and power supplies in ok state are different
            helper.add_summary('%s power supplies expected - %s power supplies ok ' % (input_pwr_sply, ps_ok_count))
            helper.status(critical)                
def run_scan():
    """
    show all available partitions
    """
    all_disks = walk_data(sess, oid_hrStorageDescr, helper)[0]
        
    print "All available disks at: " + host
    for disk in all_disks:        
        print "Disk: \t'" + disk + "'"
    quit()
def check_storage_controllers():
    """
    Check the status of the storage controllers
    Skip this check, if --noController is set
    """
    if ctrl_flag:
        ctrl = walk_data(sess, oid_ctrl, helper)[0]
        for x, data in enumerate(ctrl, 1):
            ctrl_summary_output, ctrl_long_output = state_summary(data, 'Controller %d' % x, normal_state, helper)
            add_output(ctrl_summary_output, ctrl_long_output, helper)
Esempio n. 17
0
def run_scan():
    """
    show all available partitions
    """
    all_disks = walk_data(sess, oid_hrStorageDescr, helper)[0]

    print "All available disks at: " + host
    for disk in all_disks:
        print "Disk: \t'" + disk + "'"
    quit()
Esempio n. 18
0
def check_storage_controllers():
    """
    Check the status of the storage controllers
    Skip this check, if --noController is set
    """
    if ctrl_flag:
        ctrl = walk_data(sess, oid_ctrl, helper)[0]
        for x, data in enumerate(ctrl, 1):
            ctrl_summary_output, ctrl_long_output = state_summary(data, 'Controller %d' % x, normal_state, helper)
            add_output(ctrl_summary_output, ctrl_long_output, helper)
def check_temperature_sensors():
    """
    Check all temperature sensors of the server
    All sensors with the value or threshold is -99 or 0 are ignored
    """    
    # walk all temperature sensor values and thresholds
    env_temp = walk_data(sess, oid_env_temp, helper)[0]
    env_temp_thresh = walk_data(sess, oid_env_temp_thres, helper)[0]
    env_temp_zipped = zip(env_temp, env_temp_thresh)

    for x, data in enumerate(env_temp_zipped, 1):
        # skip the check if -99 or 0 is in the value or threshold, because these data we can not use
        if '-99' not  in data and '0' not in data:
            #check if the value is over the treshold
            if int(data[0]) > int(data[1]):
                helper.add_summary('Temperature at sensor %d above threshold (%s / %s)' % (x, data[0], data[1]))
                helper.status(critical)
            # always add the sensor to the output
            helper.add_long_output('Temperature %d: %s Celsius (threshold: %s Celsius)' % (x, data[0], data[1]))
            # for the first sensor (envirnoment temperature, we add performance data)
            if x == 1:
                helper.add_metric("Environment Temperature", data[0], '', ":" + data[1], "", "", "Celsius")
def check_accesspoints(sess):
    """
    check the status of all connected access points
    """
    ap_names              = walk_data(sess, name_ap_oid, helper)[0]
    ap_operationals       = walk_data(sess, operational_ap_oid, helper)[0]
    ap_availabilitys      = walk_data(sess, availability_ap_oid, helper)[0]
    ap_alarms             = walk_data(sess, alarm_ap_oid, helper)[0]
    #ap_ip                = walk_data(sess, ip_ap_oid, helper) # no result
    
    helper.add_summary("Access Points Status")

    for x in range(len(ap_names)):
        ap_name              = ap_names[x]
        ap_operational       = ap_operationals[x]
        ap_availability      = ap_availabilitys[x]
        ap_alarm             = ap_alarms[x]               

        # Add all states to the long output
        helper.add_long_output("%s - Operational: %s - Availabilty: %s - Alarm: %s" % (ap_name, operational_states[int(ap_operational)], availability_states[int(ap_availability)], alarm_states[int(ap_alarm)]))

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

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

        # Alarm State
        if ap_alarm == "2":
            helper.status(warning)
            helper.add_summary("%s Controller Alarm State: %s" % (ap_name, alarm_states[int(ap_alarm)]))
        
        if ap_alarm == "3" or ap_alarm == "4":
            helper.status(critical)
            helper.add_summary("%s Controller Alarm State: %s" % (ap_name, alarm_states[int(ap_alarm)]))
def check_inlet(sess):
    """
    check the Inlets of Raritan PDUs
    """
    # walk the data
    inlet_values = walk_data(sess, oid_inlet_value, helper)[0]
    inlet_units = walk_data(sess, oid_inlet_unit, helper)[0]
    inlet_digits = walk_data(sess, oid_inlet_digits, helper)[0]
    inlet_states = walk_data(sess, oid_inlet_state, helper)[0]
    inlet_warning_uppers = walk_data(sess, oid_inlet_warning_upper, helper)[0]
    inlet_critical_uppers = walk_data(sess, oid_inlet_critical_upper,
                                      helper)[0]
    inlet_critical_lowers = walk_data(sess, oid_inlet_critical_lower,
                                      helper)[0]
    inlet_warning_lowers = walk_data(sess, oid_inlet_warning_lower, helper)[0]

    # just print the summary, that the inlet sensors are checked
    helper.add_summary("Inlet")

    # all list must have the same length, if not something went wrong. that makes it easier and we need less loops
    # translate the data in human readable units with help of the dicts
    for x in range(len(inlet_values)):
        inlet_unit = units[int(inlet_units[x])]
        inlet_digit = inlet_digits[x]
        inlet_state = states[int(inlet_states[x])]
        inlet_value = real_value(inlet_values[x], inlet_digit)
        inlet_warning_upper = real_value(inlet_warning_uppers[x], inlet_digit)
        inlet_critical_upper = real_value(inlet_critical_uppers[x],
                                          inlet_digit)
        inlet_warning_lower = real_value(inlet_warning_lowers[x], inlet_digit)
        inlet_critical_lower = real_value(inlet_critical_lowers[x],
                                          inlet_digit)

        if inlet_state != "normal":
            # we don't want to use the thresholds. we rely on the state value of the device
            helper.add_summary("%s %s is %s" %
                               (inlet_value, inlet_unit, inlet_state))
            helper.status(critical)

        # we always want to see the values in the long output and in the perf data
        helper.add_summary("%s %s" % (inlet_value, inlet_unit))
        helper.add_long_output("%s %s: %s" %
                               (inlet_value, inlet_unit, inlet_state))
        helper.add_metric("Sensor " + str(x), inlet_value, inlet_warning_lower +\
                          ":" + inlet_warning_upper, inlet_critical_lower + ":" +\
                          inlet_critical_upper, "", "", inlet_unit)
def check_power_redundancy():
    """
    Check if the power supplies are redundant
    The check is skipped if --noPowerRedundancy is set
    """
    # skip the check if --noPowerRedundancy is set
    if power_redundancy_flag:
        # walk the data        
        ps_redundant_data = walk_data(sess, oid_ps_redundant, helper)[0]
        
        for x, state in enumerate(ps_redundant_data, 1):
            # human readable status
            hr_status = ps_redundant_state[int(state)]
            if  hr_status != "redundant":
                # if the power supply is not redundant, we will set a critical status and add it to the summary
                helper.add_summary('Power supply %s: %s' % (x, hr_status))
                helper.status(critical)
            # we always want to see the redundancy status in the long output
            helper.add_long_output('Power supply %s: %s' % (x, hr_status))
        helper.add_long_output('')
Esempio n. 23
0
def check_power_redundancy():
    """
    Check if the power supplies are redundant
    The check is skipped if --noPowerRedundancy is set
    """
    # skip the check if --noPowerRedundancy is set
    if power_redundancy_flag:
        # walk the data
        ps_redundant_data = walk_data(sess, oid_ps_redundant, helper)[0]

        for x, state in enumerate(ps_redundant_data, 1):
            # human readable status
            hr_status = ps_redundant_state[int(state)]
            if hr_status != "redundant":
                # if the power supply is not redundant, we will set a critical status and add it to the summary
                helper.add_summary('Power supply %s: %s' % (x, hr_status))
                helper.status(critical)
            # we always want to see the redundancy status in the long output
            helper.add_long_output('Power supply %s: %s' % (x, hr_status))
        helper.add_long_output('')
def check_udp(helper, host, port, session):
    """
    the check logic for UDP ports
    """
    open_ports = walk_data(
        session, '.1.3.6.1.2.1.7.5.1.2',
        helper)[0]  # the udpLocaLPort from UDP-MIB.mib (deprecated)

    # here we show all open UDP ports
    if scan:
        print "All open UDP ports at host " + host
        for port in open_ports:
            print "UDP: \t" + port
        quit()

    if port in open_ports:
        udp_status = "OPEN"
    else:
        udp_status = "CLOSED"
        helper.status(critical)
    return ("Current status for UDP port " + port + " is: " + udp_status)
def check_fan(input_fan):
    """
    check the fans
    """
    # get a list of all fans      
    fan_data = walk_data(sess, oid_fan, helper)[0]
    
    fan_count = 0
    summary_output = ''
    long_output = ''

    for x, fan in enumerate(fan_data, 1):
        fan = int(fan)
        if normal_state[fan] == 'ok':
            # if the fan is ok, we increase the fan_count varaible
            fan_count += 1
        # we always want to the the status in the long output
        long_output += 'Fan %d: %s.\n' % (x, normal_state[fan])
    
    # check we have the correct amount ok fans in OK state, otherwise set status to critical and print the fan in the summary
    if int(fan_count) != int(input_fan):
        summary_output += '%s fan(s) expected - %s fan(s) ok. ' % (input_fan, fan_count)
        helper.status(critical)
    return (summary_output, long_output)
    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)

    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.walk_data(snmp_session, eaton_oid, a_helper)[0][0]
    eaton_check(snmp_session, a_helper, a_snmp_value)

    a_helper.check_all_metrics()

    # Print out plugin information and exit nagios-style
    a_helper.exit()
Esempio n. 27
0
    sess = netsnmp.Session(Version=version, DestHost=host, Community=community)

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

    # if no partition / disk is set, we will do a scan
    if service == "" or service is None:
        scan = True
    
    ##########
    # Here we do a scan
    ##########
    if scan:
        
        services = walk_data(sess, base_oid, helper)[0]

        if not services:
            print "No services found - SNMP disabled?"
            quit()
            
        print "Running services at host '" + host + "':\n"
        
        for service in services:
            print service
            
        if len(services) == 0:
            # if there are no running services, print the message
            print "no service running at host"
    
        # we don't want to return a icinga output, so we just end the script here
Esempio n. 28
0
    global_system_summary, global_system_long = state_summary(
        global_system_data, 'Global System', normal_state, helper)
    system_lcd_summary, system_lcd_long = state_summary(
        system_lcd_data, 'System LCD', normal_state, helper)
    global_storage_summary, global_storage_long = state_summary(
        global_storage_data, 'Global Storage', normal_state, helper)
    system_power_summary, system_power_long = state_summary(
        system_power_data, 'System Power', system_power_state, helper, 'on')

    add_output(global_system_summary, global_system_long, helper)
    add_output(system_lcd_summary, system_lcd_long, helper)
    add_output(global_storage_summary, global_storage_long, helper)
    add_output(system_power_summary, system_power_long, helper)

    # power unit
    power_unit_redundancy_data = walk_data(sess, oid_power_unit_redundancy,
                                           helper)[0]
    power_unit_name_data = walk_data(sess, oid_power_unit_name, helper)[0]
    power_unit_status_data = walk_data(sess, oid_power_unit_status, helper)[0]

    power_unit_summary_output, power_unit_long_output = power_unit_check(
        power_unit_redundancy_data, power_unit_name_data,
        power_unit_status_data)

    add_output(power_unit_summary_output, power_unit_long_output, helper)

    # chassis
    chassis_intrusion_data = walk_data(sess, oid_chassis_intrusion, helper)[0]
    chassis_intrusion_location_data = walk_data(
        sess, oid_chassis_intrusion_location, helper)[0]

    chassis_intrusion_summary_output, chassis_intrusion_long_output = chassis_intrusion_check(
Esempio n. 29
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='')
Esempio n. 30
0
    add_output(system_power_summary, system_power_long, helper)

    # power unit
    power_unit_redundancy_data = attempt_walk_data(
        sess, oid_power_unit_redundancy)[0]
    power_unit_name_data = attempt_walk_data(sess, oid_power_unit_name)[0]
    power_unit_status_data = attempt_walk_data(sess, oid_power_unit_status)[0]

    power_unit_summary_output, power_unit_long_output = power_unit_check(
        power_unit_redundancy_data, power_unit_name_data,
        power_unit_status_data)

    add_output(power_unit_summary_output, power_unit_long_output, helper)

    # chassis
    chassis_intrusion_data = walk_data(sess, oid_chassis_intrusion, helper)[0]
    chassis_intrusion_location_data = walk_data(
        sess, oid_chassis_intrusion_location, helper)[0]

    chassis_intrusion_summary_output, chassis_intrusion_long_output = chassis_intrusion_check(
        chassis_intrusion_data, chassis_intrusion_location_data)

    add_output(chassis_intrusion_summary_output, chassis_intrusion_long_output,
               helper)

    # cooling unit
    cooling_unit_name_data = walk_data(sess, oid_cooling_unit_name, helper)[0]
    cooling_unit_status_data = walk_data(sess, oid_cooling_unit_status,
                                         helper)[0]

    cooling_unit_summary_output, cooling_unit_long_output = cooling_unit_check(