#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2014             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-
# tails. 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.
#
# Author Trevor Steyn <trevor@webon.co.za>

broadsoft_as_sip_method_stats_snmp_info = ('.1.3.6.1.4.1.6431.1.2.9.1', [
						1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,	17,18,19,20,21,])

broadsoft_as_sip_method_stats_snmp_names = ['bwSipSummaryTotalTransactions','bwSipStatsInviteIns',
						'bwSipStatsInviteOuts','bwSipStatsAckIns','bwSipStatsAckOuts',
						'bwSipStatsByeIns','bwSipStatsByeOuts','bwSipStatsCancelIns',
						'bwSipStatsCancelOuts','bwSipStatsOptionsIns','bwSipStatsOptionsOuts',
						'bwSipStatsRegisterIns','bwSipStatsRegisterOuts','bwSipStatsInfoIns',
						'bwSipStatsInfoOuts','bwSipStatsNotifyIns','bwSipStatsNotifyOuts',
						'bwSipStatsPrackIns','bwSipStatsPrackOuts','bwSipStatsOtherIns',
						'bwSipStatsOtherOuts']

def inventory_broadsoft_as_sip_method_stats(info):
    if info:
        yield None, None

def check_broadsoft_as_sip_method_stats(_no_item, _no_params, info):
    perfdata = []
    this_time = time.time()
    count = 0
    for counter in info[0]:
        oid_name = broadsoft_as_sip_method_stats_snmp_names[count]
        perfdata.append((oid_name, get_rate('check_broadsoft_as_sip_method_stats' + oid_name, this_time, int(counter))))
        count += 1
		
    return (0, 'OK - Total Transactions:' + info[0][0], perfdata )

# This check works on all SNMP hosts

check_info["broadsoft_as_sip_method_stats"] = {
    'check_function':          check_broadsoft_as_sip_method_stats,
    'inventory_function':      inventory_broadsoft_as_sip_method_stats,
    'service_description':     'Broadsoft AS Methods',
    'snmp_info':               broadsoft_as_sip_method_stats_snmp_info,
    'snmp_scan_function':      lambda oid: oid(".1.3.6.1.4.1.6431.1.2.9.1.22.1.1.100") not in [ None, "" ],
    'has_perfdata':            True,
}
