1
1
"""
2
+ snmpd parser
3
+ ============
4
+ Parsers provided by this module are:
5
+
2
6
TcpIpStats - file ``/proc/net/snmp``
3
- ====================================
7
+ ------------------------------------
4
8
The ``TcpIpStats`` class implements the parsing of ``/proc/net/snmp``
5
9
file, which contains TCP/IP stats of individual layer.
6
10
9
13
The ``TcpIpStatsIPV6`` class implements the parsing of ``/proc/net/snmp6``
10
14
file, which contains TCP/IP stats of individual layer.
11
15
16
+
17
+ SnmpdConf - file ``/etc/snmp/snmpd.conf``
18
+ -----------------------------------------
19
+ The ``SnmpdConf`` class implements the parsing of ``/etc/snmp/snmpd.conf``
20
+ file, which is the configuration file for the Net-SNMP SNMP agent.
12
21
"""
13
22
14
- from .. import Parser , parser , LegacyItemAccess
23
+ from insights .core import LegacyItemAccess , Parser
24
+ from insights .core .exceptions import ParseException
25
+ from insights .core .plugins import parser
26
+ from insights .parsers import get_active_lines
15
27
from insights .specs import Specs
16
28
17
29
@@ -38,14 +50,13 @@ class TcpIpStats(Parser, LegacyItemAccess):
38
50
... UdpLite: InDatagrams NoPorts InErrors OutDatagrams RcvbufErrors SndbufErrors InCsumErrors IgnoredMulti
39
51
... UdpLite: 0 0 0 0 0 0 0 0
40
52
... '''.strip()
41
- >>> from insights.tests import context_wrap
42
- >>> shared = {TcpIpStats: TcpIpStats(context_wrap(SNMP_CONTENT))}
43
- >>> stats = shared[TcpIpStats]
44
- >>> snmp_stats = stats.get("Ip")
45
- >>> print snmp_stats["DefaultTTL"]
53
+ >>> type(proc_snmp_ipv4)
54
+ <class 'insights.parsers.snmp.TcpIpStats'>
55
+ >>> snmp_stats = proc_snmp_ipv4.get("Ip")
56
+ >>> snmp_stats["DefaultTTL"]
46
57
64
47
- >>> snmp_stats = stats .get("Udp")
48
- >>> print snmp_stats["InDatagrams"]
58
+ >>> snmp_stats = proc_snmp_ipv4 .get("Udp")
59
+ >>> snmp_stats["InDatagrams"]
49
60
18905
50
61
51
62
@@ -109,15 +120,14 @@ class TcpIpStatsIPV6(Parser, LegacyItemAccess):
109
120
... Ip6InOctets 579410
110
121
... Icmp6OutErrors 0
111
122
... Icmp6InCsumErrors 0
112
- ...'''.strip()
113
- >>> from insights.tests import context_wrap
114
- >>> shared = {TcpIpStatsIPV6: TcpIpStatsIPV6(context_wrap(SNMP_CONTENT))}
115
- >>> stats = shared[TcpIpStatsIPV6]
116
- >>> IP6_RX_stats = stats.get("Ip6InReceives")
117
- >>> print IP6_RX_stats
123
+ ... '''.strip()
124
+ >>> type(proc_snmp_ipv6)
125
+ <class 'insights.parsers.snmp.TcpIpStatsIPV6'>
126
+ >>> IP6_RX_stats = proc_snmp_ipv6.get("Ip6InReceives")
127
+ >>> IP6_RX_stats
118
128
757
119
- >>> IP6_In_Disc = stats .get("Ip6InDiscards")
120
- >>> print IP6_In_Disc
129
+ >>> IP6_In_Disc = proc_snmp_ipv6 .get("Ip6InDiscards")
130
+ >>> IP6_In_Disc
121
131
10
122
132
123
133
@@ -141,3 +151,51 @@ def parse_content(self, content):
141
151
line_split = line .split ()
142
152
snmp6_stats [line_split [0 ]] = int (line_split [1 ]) if len (line_split ) > 1 and line_split [1 ] else None
143
153
self .data = snmp6_stats
154
+
155
+
156
+ @parser (Specs .snmpd_conf )
157
+ class SnmpdConf (Parser , dict ):
158
+ """
159
+ Class for parsing the file ``/etc/snmp/snmpd.conf``
160
+
161
+ Sample file content::
162
+
163
+ # sec.name source community
164
+ com2sec notConfigUser default public
165
+
166
+ # groupName securityModel securityName
167
+ group notConfigGroup v1 notConfigUser
168
+ group notConfigGroup v2c notConfigUser
169
+
170
+ # Make at least snmpwalk -v 1 localhost -c public system fast again.
171
+ # name incl/excl subtree mask(optional)
172
+ view systemview included .1.3.6.1.2.1.1
173
+ view systemview included .1.3.6.1.2.1.25.1.1
174
+
175
+ # group context sec.model sec.level prefix read write notif
176
+ access notConfigGroup "" any noauth exact systemview none none
177
+
178
+ dontLogTCPWrappersConnects yes
179
+ include_ifmib_iface_prefix eth enp1s0
180
+
181
+ Examples:
182
+ >>> type(snmpd_conf)
183
+ <class 'insights.parsers.snmp.SnmpdConf'>
184
+ >>> snmpd_conf['dontLogTCPWrappersConnects']
185
+ ['yes']
186
+ >>> snmpd_conf['include_ifmib_iface_prefix']
187
+ ['eth enp1s0']
188
+ """
189
+
190
+ def parse_content (self , content ):
191
+ content = get_active_lines (content )
192
+ if not content :
193
+ raise ParseException ('Empty Content' )
194
+
195
+ for line in content :
196
+ parts = line .split (None , 1 )
197
+ key = parts [0 ].strip ()
198
+ self .setdefault (key , [])
199
+ if len (parts ) > 1 :
200
+ value = parts [1 ].strip ()
201
+ self [key ].append (value )
0 commit comments