From a2e419b232c02320f7bffacc6d33befdbb46565f Mon Sep 17 00:00:00 2001
From: "th.l" <thl-cmk@outlook.com>
Date: Tue, 26 Jul 2022 22:03:09 +0200
Subject: [PATCH] update project

---
 agent_based/inv_opengear_serial_lines.py      | 151 ++++++++++++++++++
 inv_opengear_serial_line.mkp                  | Bin 0 -> 2286 bytes
 packages/inv_opengear_serial_line             |  12 ++
 .../views/inv_opengear_serial_lines.py        |  42 +++++
 4 files changed, 205 insertions(+)
 create mode 100644 agent_based/inv_opengear_serial_lines.py
 create mode 100644 inv_opengear_serial_line.mkp
 create mode 100644 packages/inv_opengear_serial_line
 create mode 100644 web/plugins/views/inv_opengear_serial_lines.py

diff --git a/agent_based/inv_opengear_serial_lines.py b/agent_based/inv_opengear_serial_lines.py
new file mode 100644
index 0000000..8788118
--- /dev/null
+++ b/agent_based/inv_opengear_serial_lines.py
@@ -0,0 +1,151 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# License: GNU General Public License v2
+#
+# Author: thl-cmk[at]outlook[dot]com
+# URL   : https://thl-cmk.hopto.org
+# Date  : 20212-07-08
+# File  : inv_opengear_serial_line
+#
+# inventory of opengear console servers serial lines
+#
+#
+
+from cmk.base.plugins.agent_based.agent_based_api.v1 import (
+    register,
+    SNMPTree,
+    TableRow,
+    startswith,
+    OIDEnd,
+)
+from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import (
+    StringTable,
+    InventoryResult,
+)
+
+_opengear_state = {
+    '1': 'on',
+    '2': 'off',
+}
+
+_opengear_log_level = {
+    '1': 'disabled',
+    '2': 'connect',
+    '3': 'inputAndOutput',
+    '4': 'inputOnly',
+    '5': 'outputOnly',
+}
+
+_opengear_mode = {
+    '1': 'none',
+    '2': 'console',
+    '3': 'sdt',
+    '4': 'terminal',
+    '5': 'bridge',
+}
+
+_opengear_flow_control = {
+    '1': 'none',
+    '2': 'hardware',
+    '3': 'software',
+}
+
+_opengear_stop_bits = {
+    '1': 'one',
+    '2': 'two',
+    '3': 'oneAndAHalf',
+}
+
+_opengear_parity = {
+    '1': 'none',
+    '2': 'odd',
+    '3': 'even',
+    '4': 'mark',
+    '5': 'space',
+}
+
+
+def parse_inv_opengear_serial_lines(string_table: StringTable):
+    section = []
+
+    for index, label, speed, databits, parity, stopbits, flowcontrol, mode, loglevel, dcd, dtr, dsr, cts, rts in string_table:
+        entry = {
+            'key_columns': {
+                'index': index
+            },
+            'inventory_columns': {
+                'label': label,
+                'speed': speed,
+                'databits': databits,
+                'parity': _opengear_parity.get(parity, parity),
+                'stopbits': _opengear_stop_bits.get(stopbits, stopbits),
+                'flowcontrol': _opengear_flow_control.get(flowcontrol, flowcontrol),
+                'mode': _opengear_mode.get(mode, mode),
+                'loglevel': _opengear_log_level.get(loglevel, loglevel),
+                'cts': _opengear_state[cts],
+
+                'dcd': _opengear_state[dcd],
+                'dtr': _opengear_state[dtr],
+                'rts': _opengear_state[rts],
+            },
+            'status_columns': {
+
+            }
+        }
+
+        section.append(entry)
+
+    return section
+
+
+def inventory_bgp_peers(params, section) -> InventoryResult:
+    path = ['hardware', 'serial_lines']
+
+    for entry in section:
+        yield TableRow(
+            path=path,
+            key_columns=entry['key_columns'],
+            inventory_columns=entry['inventory_columns'],
+            status_columns=entry['status_columns']
+        )
+
+
+register.snmp_section(
+    name='inv_opengear_serial_lines',
+    parse_function=parse_inv_opengear_serial_lines,
+    fetch=SNMPTree(
+        base='.1.3.6.1.4.1.25049.17.2.1',  # OG-STATUSv2-MIB:orgSerialPortEntry
+        oids=[
+            OIDEnd(),  # line index
+            '2',  # ogSerialPortLabel
+            '3',  # ogSerialPortSpeed
+            '4',  # ogSerialPortDataBits
+            '5',  # ogSerialPortParity
+            '6',  # ogSerialPortStopBits
+            '7',  # ogSerialPortFlowControl
+            '8',  # ogSerialPortMode
+            '9',  # ogSerialPortLogLevel
+            # '10',  # ogSerialPortRxBytes
+            # '11',  # ogSerialPortTxBytes
+            # '12',  # ogSerialPortFramingErrors
+            # '13',  # ogSerialPortParityErrors
+            # '14',  # ogSerialPortOverrunErrors
+            # '15',  # ogSerialPortBreaks
+            '16',  # ogSerialPortDCD
+            '17',  # ogSerialPortDTR
+            '18',  # ogSerialPortDSR
+            '19',  # ogSerialPortCTS
+            '20',  # ogSerialPortRTS
+        ]
+    ),
+    detect=startswith('.1.3.6.1.2.1.1.2.0', '.1.3.6.1.4.1.25049'),  # sysObjectID == opengear
+)
+
+register.inventory_plugin(
+    name='inv_opengear_serial_lines',
+    inventory_function=inventory_bgp_peers,
+    inventory_default_parameters={
+    },
+    inventory_ruleset_name='inv_opengear_serial_lines',
+)
diff --git a/inv_opengear_serial_line.mkp b/inv_opengear_serial_line.mkp
new file mode 100644
index 0000000000000000000000000000000000000000..9949d8527ebe1c903422bcdac9a1faad84a02c72
GIT binary patch
literal 2286
zcmV<K2od)miwFpNNZ?`u|7mV^UvF?_Zf9j-a$j?0a%o{~Uu<b^Wi2u=GBPkXFgPxD
zE-)@IE-@}`Yj6PVTWxRKI1<ih{R&?4!S=#YY}tuZ174s_+Fr0}Q^f9l$pwOJ(Y7|S
zsG}%njUxYjht!KjNlx6uHj85C32Iy9%y2kEK9uaK7tGng4@L)Y*6*u#K>583e+S*Z
zHRyEu{qCT5AX~cq1JXHo1;mkXIJojxOtLt+p9J3;PAry;H-@A!S(?`-X^N$PJX<~7
zIpUth!e{K^&Sm0$##XIH+aL{>Ml<e(!efEdx(e1b5R7lgoN>ZJ8Z4;8$#4JpL|nS|
zW;7xZ<(}gc-wSB;-yku<9s{2_t{rn<T3HGaM#GbnbZ~RYLcvVN7fO2W`7{DC@OA-%
z*;6N?E?nO=ykKo-W7^3$wi?F_H;sGH-J<bGr%EUE<AoPQCu@&BMkmi(c#^{h&WcJW
zcZn(=gLq|Uep<3Yc*0j|c}xm%AYK+WrM#v*O5<sDEUPo<oSSR21ApCOzq#@Po74Zr
z9#`{kSW-rl2%Xsj1j$WJb<NHj)6zxa$eH@ojsxMz*negLeL6t=BjEx6o4-da`1|<3
z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v0f+Yx@gx!66xh
z^gq}oQ&T?MY;G@El+|LUKg#Y3!!Kr5TKBCOge%q9YQL<W71C+ys`6tm^{mcLQ&%M+
zd#M-7@H7juT!g5OeXQhVdYX-->S4cGZ0q#&i9q}QZs<jNnju+*LbASnY|X09TujFM
z#dKCl$mPZ5eyXZ!PFJ1W?xo7B4&UYuKec2nTMY*^ON(EXQ|#FA?V8<PZNf?f1OkCT
zAP@)y0)apv5C{YUfj}S-2m}IwKp+qZ1OkCTAP@)y0)apv5C{YUfj}S-h@TLD0v3^p
I7XWww0P0nIR{#J2

literal 0
HcmV?d00001

diff --git a/packages/inv_opengear_serial_line b/packages/inv_opengear_serial_line
new file mode 100644
index 0000000..2d1401a
--- /dev/null
+++ b/packages/inv_opengear_serial_line
@@ -0,0 +1,12 @@
+{'author': 'Th.L. (thl-cmk[at]outlook[dot]com)',
+ 'description': 'Inventory for opengear KVM devices serial lines\n',
+ 'download_url': 'https://thl-cmk.hopto.org',
+ 'files': {'agent_based': ['inv_opengear_serial_lines.py'],
+           'web': ['plugins/views/inv_opengear_serial_lines.py']},
+ 'name': 'inv_opengear_serial_line',
+ 'num_files': 2,
+ 'title': 'opengear serial line inventory',
+ 'version': '20220708.v.0.0.1',
+ 'version.min_required': '2.0.0',
+ 'version.packaged': '2021.09.20',
+ 'version.usable_until': None}
\ No newline at end of file
diff --git a/web/plugins/views/inv_opengear_serial_lines.py b/web/plugins/views/inv_opengear_serial_lines.py
new file mode 100644
index 0000000..ba5d752
--- /dev/null
+++ b/web/plugins/views/inv_opengear_serial_lines.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# License: GNU General Public License v2
+#
+# Author: thl-cmk[at]outlook[dot]com
+# URL   : https://thl-cmk.hopto.org
+# Date  : 2022-07-08
+# File  : view/inv_opengear_serial_lines
+#
+
+from cmk.gui.i18n import _
+from cmk.gui.plugins.views import (
+    inventory_displayhints,
+)
+
+from cmk.gui.plugins.views.inventory import declare_invtable_view
+
+inventory_displayhints.update({
+    '.hardware.serial_lines:': {
+        'title': _('Serial lines'),
+        'keyorder': [
+            'index',
+            'label', 
+            'speed', 'databits', 'parity', 'stopbits', 'flowcontrol'
+        ],
+        'view': 'invseriallines_of_host',
+    },
+    '.hardware.serial_lines:*.index': {'title': _('Index'), },
+    '.hardware.serial_lines:*.label': {'title': _('Label'), },
+    '.hardware.serial_lines:*.speed': {'title': _('Speed'), },
+    '.hardware.serial_lines:*.databits': {'title': _('Data bits'), },
+    '.hardware.serial_lines:*.parity': {'title': _('Parity'), },
+    '.hardware.serial_lines:*.stopbits': {'title': _('Stop bits'), },
+    '.hardware.serial_lines:*.flowcontrol': {'title': _('Flow control'), },
+    '.hardware.serial_lines:*.cts': {'title': _('CTS'), },
+    '.hardware.serial_lines:*.dcd': {'title': _('DCD'), },
+    '.hardware.serial_lines:*.dtr': {'title': _('DTR'), },
+    '.hardware.serial_lines:*.rts': {'title': _('RTS'), },
+})
+
+declare_invtable_view('invseriallines', '.hardware.serial_lines:', _('Serial lines'), _('Serial lines'))
-- 
GitLab