#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2017             mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software;  you can redistribute it and/or modify it
# under the  terms of the  GNU General Public License  as published by
# the Free Software Foundation in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# ails.  You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.

#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.3.1.1 "BATT 3.0V"
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.3.1.2 "STBY 12V"
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.3.1.3 "STBY 5V"
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.3.1.4 "STBY 3.3V"
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.3.1.5 "LAN 1.8V STBY"
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.3.1.6 "iRMC 1.5V STBY"
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.3.1.7 "LAN 1.0V STBY"
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.3.1.8 "MAIN 12V"
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.3.1.9 "MAIN 5V"
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.4.1.1 3
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.4.1.2 3
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.4.1.3 3
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.4.1.4 3
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.4.1.5 3
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.4.1.6 3
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.4.1.7 3
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.4.1.8 3
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.4.1.9 3
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.5.1.1 3270
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.5.1.2 11880
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.5.1.3 5100
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.5.1.4 3350
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.5.1.5 1800
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.5.1.6 1460
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.5.1.7 980
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.5.1.8 12160
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.5.1.9 4980
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.7.1.1 2010
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.7.1.2 11280
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.7.1.3 4630
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.7.1.4 3020
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.7.1.5 1670
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.7.1.6 1390
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.7.1.7 930
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.7.1.8 11310
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.7.1.9 4630
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.8.1.1 3500
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.8.1.2 12960
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.8.1.3 5420
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.8.1.4 3570
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.8.1.5 1930
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.8.1.6 1610
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.8.1.7 1080
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.8.1.8 12900
#.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1.8.1.9 5420


def parse_fsc_sc2_voltage(info):
    parsed = {}
    for designation, value, min_value, max_value in info:
        try:
            value = float(value)/1000.0
            min_value = float(min_value)/1000.0
            max_value = float(max_value)/1000.0
        except ValueError:
            dev_state = 3, 'Could not get all values'
            parsed.setdefault(designation, {"device_state": dev_state})
        else:
            dev_state = value
            if value < min_value:
                dev_state = value, (2, 'too low, deceeds %.2f V' % min_value)
            elif value >= max_value:
                dev_state = value, (2, 'too high, exceeds %.2f V' % max_value)
            parsed.setdefault(designation, {"voltage": dev_state})
    return parsed


check_info['fsc_sc2_voltage'] = {
    'parse_function'            : parse_fsc_sc2_voltage,
    'inventory_function'        : inventory_elphase,
    'check_function'            : check_elphase,
    'service_description'       : 'Voltage %s',
    'snmp_info'                 : ('.1.3.6.1.4.1.231.2.10.2.2.10.6.3.1', [
                                      '3',    #sc2VoltageDesignation
                                      '5',    #sc2VoltageCurrentValue
                                      '7',    #sc2VoltageMinimumLevel
                                      '8',    #sc2VoltageMaximumLevel
                                  ]),
    'snmp_scan_function'        : lambda oid: oid('.1.3.6.1.4.1.231.2.10.2.2.10.1.1.0'),
    'group'                     : 'el_inphase',
    'includes'                  : ['elphase.include'],
}
