get_capabilities.py 4.66 KB
Newer Older
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
1
2
3
# ---------------------------------------------------------------------
# Eltex.MES.get_capabilities
# ---------------------------------------------------------------------
4
# Copyright (C) 2007-2021 The NOC Project
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
5
6
7
8
9
# See LICENSE for details
# ---------------------------------------------------------------------

# Python modules
import re
Dmitry Volodin's avatar
Dmitry Volodin committed
10

Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
11
# NOC modules
kk's avatar
kk committed
12
from noc.core.text import parse_table
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
13
from noc.sa.profiles.Generic.get_capabilities import Script as BaseScript
14
15
from noc.sa.profiles.Generic.get_capabilities import false_on_cli_error, false_on_snmp_error
from noc.core.mib import mib
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
16
17
18
19
20
21


class Script(BaseScript):
    name = "Eltex.MES.get_capabilities"

    rx_lldp_en = re.compile(r"LLDP state: Enabled?")
MaksimSmile13's avatar
MaksimSmile13 committed
22
    rx_lacp_en = re.compile(r"\s+Partner[\S\s]+?\s+Oper Key:\s+1", re.MULTILINE)
MaksimSmile13's avatar
MaksimSmile13 committed
23
    rx_gvrp_en = re.compile(r"GVRP Feature is currently Enabled on the device?")
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
24
25
26
    rx_stp_en = re.compile(r"Spanning tree enabled mode?")

    @false_on_cli_error
27
    def has_lldp_cli(self):
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
28
29
30
31
32
33
        """
        Check box has lldp enabled on Eltex
        """
        cmd = self.cli("show lldp configuration", ignore_errors=True)
        return self.rx_lldp_en.search(cmd) is not None

34
    @false_on_snmp_error
35
36
37
38
    def has_lldp_snmp(self):
        """
        Check box has lldp enabled on Eltex
        """
39
        r = self.snmp.get(mib["LLDP-MIB::lldpStatsRemTablesInserts", 0])
40
        if r:
41
42
            return True

Maksim13's avatar
Maksim13 committed
43
    @false_on_cli_error
44
    def has_lacp_cli(self):
Maksim13's avatar
Maksim13 committed
45
46
47
48
49
50
        """
        Check box has lacp enabled on Eltex
        """
        cmd = self.cli("show lacp Port-Channel", ignore_errors=True)
        return self.rx_lacp_en.search(cmd) is not None

51
52
53
54
55
56
57
58
59
60
    @false_on_snmp_error
    def has_lacp_snmp(self):
        """
        Check box has lacp enabled on Eltex
        """
        for oid, value in self.snmp.getnext(mib["IEEE8023-LAG-MIB::dot3adAggPortPartnerOperKey"]):
            if value:
                return True
        return False

Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
61
    @false_on_cli_error
62
    def has_stp_cli(self):
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
63
64
65
66
67
68
        """
        Check box has stp enabled on Eltex
        """
        cmd = self.cli("show spanning-tree", ignore_errors=True)
        return self.rx_stp_en.search(cmd) is not None

69
70
71
72
73
74
75
76
77
    @false_on_snmp_error
    def has_stp_snmp(self):
        """
        Check box has stp enabled on Eltex
        """
        # RADLAN-BRIDGEMIBOBJECTS-MIB::rldot1dStpEnable
        r = self.snmp.get("1.3.6.1.4.1.89.57.2.3.0")
        return r == 1

Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
78
    @false_on_cli_error
79
    def has_gvrp_cli(self):
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
80
81
82
83
84
85
86
87
88
89
90
91
92
        """
        Check box has gvrp enabled on Eltex
        """
        cmd = self.cli("show gvrp configuration", ignore_errors=True)
        return self.rx_gvrp_en.search(cmd) is not None
        # Get GVRP interfaces

    @false_on_cli_error
    def has_stack(self):
        """
        Check stack members
        :return:
        """
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
93
        r = self.cli("show version", cached=True)
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
94
95
96
        s = [e[0] for e in parse_table(r)]
        if not s:  # MES3324
            r = self.cli("show system", cached=True)
97
98
99
            if "Unit" not in r:  # MES3108F
                return []
            s = [e[0] for e in parse_table(r, footer=r"^Unit\s*(?:Main Power|Fans Status)")]
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
100
101
102
            while s[-1] == "":
                del s[-1]
        return s
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
103

104
105
106
107
108
109
110
    @false_on_snmp_error
    def has_stack_snmp(self):
        """
        Check stack members
        :return:
        """
        r = []
111
112
113
        mode = self.snmp.get(mib["RADLAN-STACK-MIB::rlStackUnitMode", 0])
        if mode == 1:
            return []
114
115
116
        for oid, stack_num in self.snmp.getnext(
            mib["RADLAN-STACK-MIB::rlStackActiveUnitIdAfterReset"]
        ):
117
118
119
            # In some rare cases, returned 0, if only one device in stack
            if stack_num == 0:
                stack_num = 1
120
121
122
            r += [str(stack_num)]
        return r

123
124
125
126
127
128
129
130
131
    @false_on_snmp_error
    def has_qos_interface_stats(self):
        # eltCountersQosStatisticsEnable
        # On config enabled by 'qos statistics interface'
        r = self.snmp.get("1.3.6.1.4.1.35265.1.23.1.8.1.1.2.1.0")
        if r == 1:
            # qos statistics interface
            return True

132
    def execute_platform_cli(self, caps):
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
133
134
        s = self.has_stack()
        if s:
MaksimSmile13's avatar
MaksimSmile13 committed
135
            caps["Stack | Members"] = len(s) if len(s) >= 1 else 0
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
136
            caps["Stack | Member Ids"] = " | ".join(s)
137
138
139
        s = self.has_qos_interface_stats()
        if s:
            caps["Metrics | QOS | Statistics"] = True
140
141
142
143
144
145

    def execute_platform_snmp(self, caps):
        s = self.has_stack_snmp()
        if s:
            caps["Stack | Members"] = len(s) if len(s) >= 1 else 0
            caps["Stack | Member Ids"] = " | ".join(s)
146
147
148
        s = self.has_qos_interface_stats()
        if s:
            caps["Metrics | QOS | Statistics"] = True