#!/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.

# Example SNMP walk:
#
# InTaskName: The actual name of the task as it appears in the SERVER.TASK statistic on the server.
# .1.3.6.1.4.1.334.72.1.1.6.1.2.1.4.0 Router
# .1.3.6.1.4.1.334.72.1.1.6.1.2.1.4.1 tm_grab Subsystems
# .1.3.6.1.4.1.334.72.1.1.6.1.2.1.4.2 tm_grab M01
# .1.3.6.1.4.1.334.72.1.1.6.1.2.1.4.3 tm_grab M02
# .1.3.6.1.4.1.334.72.1.1.6.1.2.1.4.4 tm_grab M03
# .1.3.6.1.4.1.334.72.1.1.6.1.2.1.4.5 tm_grab M04
# .1.3.6.1.4.1.334.72.1.1.6.1.2.1.4.6 tm_grab M05
# .1.3.6.1.4.1.334.72.1.1.6.1.2.1.4.7 tm_grab
# .1.3.6.1.4.1.334.72.1.1.6.1.2.1.4.8 Router

inv_domino_tasks_rules = []

# Deprecated option since 1.6. cmk_base creates a config warning when finding rules
# for this ruleset. Can be dropped with 1.7.
inv_domino_tasks = []


# Bring the SNMP data in the format expected by the common ps functions.
# e.g.:
# [None, (u'root', u'185292', u'5804', u'00:00:02/03:33:13', u'1'), u'/sbin/init', u'splash']
def parse_domino_tasks(info):
    parsed = []
    for line in info:
        node, task_name = line
        # node, process_info, command_line
        parsed.append((node, ps_info(), task_name))
    return parsed


def inventory_domino_tasks(parsed):
    return inventory_ps_common(inv_domino_tasks_rules, parsed)


def check_domino_tasks(item, params, parsed):
    return check_ps_common(item, params, parsed, info_name="Tasks")


check_info['domino_tasks'] = {
    "parse_function": parse_domino_tasks,
    "check_function": check_domino_tasks,
    "inventory_function": inventory_domino_tasks,
    "has_perfdata": True,
    "group": "domino_tasks",
    "service_description": "Domino Task %s",
    "includes": ["ps.include"],
    "node_info": True,  # add first column with actual host name
    "snmp_scan_function": lambda oid: oid(".1.3.6.1.2.1.1.2.0") == ".1.3.6.1.4.1.311.1.1.3.1.2",
    "snmp_info": (
        ".1.3.6.1.4.1.334.72.1.1.6.1.2.1",
        [
            4,  # InTaskName
        ]),
}
