Projet

Général

Profil

Révision ba732fd7

IDba732fd7ec3226e9f15d81df8d41e343b5ac58fc
Parent dacb5501
Enfant 275c82f4

Ajouté par Lars Kruse il y a plus de 6 ans

Plugin snmp__airport: fix code style issues reported by flake8

Voir les différences:

plugins/snmp/snmp__airport
49 49
On Debian/Ubuntu machines this package is named 'libsnmp-python'"""
50 50
    sys.exit(-3)
51 51

  
52
DEBUG=None
53
CMDS=['type', 'rates', 'time', 'lastrefresh', 'signal', 'noise', 'rate', 'rx',
54
      'tx', 'rxerr', 'txerr']
55
CMD=None
56
DESTHOST=None
57
NUMCLIENTS=None
58
NUMDHCPCLIENTS=None
59
WANIFINDEX=None
52
DEBUG = None
53
CMDS = ['type', 'rates', 'time', 'lastrefresh', 'signal', 'noise', 'rate', 'rx', 'tx', 'rxerr',
54
        'txerr']
55
CMD = None
56
DESTHOST = None
57
NUMCLIENTS = None
58
NUMDHCPCLIENTS = None
59
WANIFINDEX = None
60

  
60 61

  
61 62
def dbg(text):
62 63
    """Print some debugging text if DEBUG=1 is in our environment"""
63 64
    if DEBUG is not None:
64 65
        print "DEBUG: %s" % text
65 66

  
67

  
66 68
def usage():
67 69
    """Print some usage information about ourselves"""
68 70
    print __doc__
69 71

  
72

  
70 73
def parseName(name):
71 74
    """Examing argv[0] (i.e. the name of this script) for the hostname we should
72 75
    be talking to and the type of check we want to run. The hostname should be
......
88 91
        dbg("parseName found an inconsistent name: '%s'" % name)
89 92
        return None
90 93

  
94

  
91 95
def tableToDict(table, num):
92 96
    """The netsnmp library returns a tuple with all of the data, it is not in any
93 97
    way formatted into rows. This function converts the data into a structured
......
129 133

  
130 134
    return clientTable
131 135

  
136

  
132 137
def getNumClients():
133 138
    """Returns the number of wireless clients connected to the Airport we are
134 139
    examining. This will only ever be polled via SNMP once per invocation. If
......
148 153
    dbg("getNumClients: found %d clients" % NUMCLIENTS)
149 154
    return NUMCLIENTS
150 155

  
156

  
151 157
def getNumDHCPClients():
152 158
    """Returns the number of DHCP clients with currently active leases. This
153 159
    will only ever be polled via SNMP once per invocation. If called a second
......
167 173
    dbg("getNumDHCPClients: found %d clients" % NUMDHCPCLIENTS)
168 174
    return NUMDHCPCLIENTS
169 175

  
176

  
170 177
def getExternalInterface():
171 178
    """Returns the index of the WAN interface of the Airport. This will only
172 179
    ever be polled via SNMP once per invocation, per getNum*Clients(). See
......
176 183

  
177 184
    if WANIFINDEX is None:
178 185
        interfaces = list(netsnmp.snmpwalk(netsnmp.Varbind(iFaceNames),
179
                                          Version=2, DestHost=DESTHOST,
180
                                          Community='public'))
186
                                           Version=2, DestHost=DESTHOST,
187
                                           Community='public'))
181 188
        dbg("getExternalInterface: found interfaces: %s" % interfaces)
182 189
        try:
183 190
            WANIFINDEX = interfaces.index('mgi1') + 1
......
189 196
    dbg("getExternalInterface: found mgi1 at index: %d" % WANIFINDEX)
190 197
    return WANIFINDEX
191 198

  
199

  
192 200
def getExternalInOctets():
193 201
    """Returns the number of octets of inbound traffic on the WAN interface"""
194 202
    return getOctets('In')
195 203

  
204

  
196 205
def getExternalOutOctets():
197 206
    """Returns the number of octets of outbound traffic on the WAN interface"""
198 207
    return getOctets('Out')
199 208

  
209

  
200 210
def getOctets(direction):
201 211
    """Returns the number of octets of traffic on the WAN interface in the
202 212
    requested direction"""
......
211 221
                               Version=2, DestHost=DESTHOST,
212 222
                               Community='public')[0])
213 223

  
224

  
214 225
def getWanSpeed():
215 226
    """Returns the speed of the WAN interface"""
216 227
    ifSpeed = "1.3.6.1.2.1.2.2.1.5.%s" % getExternalInterface()
......
219 230
        wanSpeed = int(netsnmp.snmpget(netsnmp.Varbind(ifSpeed),
220 231
                                       Version=2, DestHost=DESTHOST,
221 232
                                       Community='public')[0])
222
    except:
233
    except:  # noqa: E722 (TODO: specify the expected exceptions)
223 234
        dbg("getWanSpeed: Unable to probe for data, defaultint to 10000000")
224 235
        wanSpeed = 10000000
225 236

  
226 237
    return wanSpeed
227 238

  
239

  
228 240
def getData():
229 241
    """Returns a dictionary populated with all of the wireless clients and their
230 242
    metadata"""
......
246 258

  
247 259
    return clients
248 260

  
261

  
249 262
def main(clients=None):
250 263
    """This function fetches metadata about wireless clients if needed, then
251 264
    displays whatever values have been requested"""
......
263 276
        for client in clients:
264 277
            print "MAC_%s.value %s" % (client, clients[client][CMD])
265 278

  
279

  
266 280
if __name__ == '__main__':
267 281
    clients = None
268 282
    if os.getenv('DEBUG') == '1':
......
352 366
            sys.exit(0)
353 367
    else:
354 368
        main(clients)
355

  
t/test-exception-wrapper.expected-failures
412 412
plugins/sge/sge_queue_
413 413
plugins/sge/sge_queue_xml_
414 414
plugins/smstools/smstools_
415
plugins/snmp/snmp__airport
416 415
plugins/snmp/snmp___bri_se_
417 416
plugins/snmp/snmp__brocade_ifs
418 417
plugins/snmp/snmp__fn

Formats disponibles : Unified diff