Projet

Général

Profil

Révision 7063330e

ID7063330e031922c63012990543e917a5d85cd25d
Parent 73f885e3
Enfant 86bee016

Ajouté par Lars Kruse il y a presque 6 ans

Fix python style issues reported by flake8

Additionally some python2-only "print" statements are now compatible
with python3.

Voir les différences:

plugins/bacula/bacula_job
100 100

  
101 101
        # Get the current bytes
102 102
        if line.endswith(" is running."):
103
            bytes_count_text = input_lines[pos+2].split()[1].split("=")[1].replace(",", "")
103
            bytes_count_text = input_lines[pos + 2].split()[1].split("=")[1].replace(",", "")
104 104
            try:
105 105
                # python2
106 106
                bytes_count = long(bytes_count_text)
......
126 126
    print("graph_category backup")
127 127
    print("graph_order", " ".join(fd[1] for fd in clients))
128 128
    print()
129
    if ((os.getenv("report_hostname") is not None) and
130
            (os.getenv("report_hostname").upper() in ["YES", "TRUE", "1", "Y"])):
129
    if ((os.getenv("report_hostname") is not None)
130
            and (os.getenv("report_hostname").upper() in ["YES", "TRUE", "1", "Y"])):
131 131
        print("host_name", hostname)
132 132
    for client in clients:
133 133
        print("%s.label %s" % (client[1], client[0]))
plugins/bacula/bacula_sd
91 91

  
92 92
        # Get the current bytes
93 93
        if input_lines[pos].endswith("is mounted with:"):
94
            bytes_count_text = input_lines[pos+5].split()[1].split("=")[1].replace(",", "")
94
            bytes_count_text = input_lines[pos + 5].split()[1].split("=")[1].replace(",", "")
95 95
            try:
96 96
                bytes_count = long(bytes_count_text)
97 97
            except NameError:
plugins/currency/bitcoin/bitcoind_
236 236
            'method': self.method,
237 237
            'params': args,
238 238
            'id': self.id,
239
            }
239
        }
240 240
        request = urllib.request.Request(self.service.url, json.dumps(data).encode())
241 241
        if self.service.username:
242 242
            auth_string = '%s:%s' % (self.service.username, self.service.password)
plugins/currency/bitcoin/btcguild_hashrate_
7 7
import json
8 8

  
9 9
URL = 'https://www.btcguild.com/api.php?api_key='
10
API_KEY = sys.argv[0][(sys.argv[0].rfind('_')+1):]
10
API_KEY = sys.argv[0][(sys.argv[0].rfind('_') + 1):]
11 11

  
12 12
STATS = URL + API_KEY
13 13

  
14
print STATS
14
print(STATS)
15 15

  
16 16
command = ''
17 17
if len(sys.argv) > 1:
......
25 25

  
26 26

  
27 27
if command == 'config':
28
    print "graph_title BTCGuild Hashrate"
29
    print "graph_args --upper-limit 3000 -l 0"
30
    print "graph_vlabel MHash/s"
31
    print "graph_category htc"
28
    print("graph_title BTCGuild Hashrate")
29
    print("graph_args --upper-limit 3000 -l 0")
30
    print("graph_vlabel MHash/s")
31
    print("graph_category htc")
32 32
    for worker in workers:
33 33
        label = workers[worker]['worker_name']
34
        print label + ".label " + label
34
        print(label + ".label " + label)
35 35
    sys.exit(0)
36 36

  
37 37
for worker in workers:
38
        hash_rate = workers[worker]['hash_rate']
39
        label = workers[worker]['worker_name']
40
        print label + ".value %d" % int(hash_rate)
38
    hash_rate = workers[worker]['hash_rate']
39
    label = workers[worker]['worker_name']
40
    print(label + ".value %d" % int(hash_rate))
plugins/lighttpd/lighttpd_
53 53

  
54 54

  
55 55
program = sys.argv[0]
56
graph_type = program[program.rfind("_")+1:]
56
graph_type = program[program.rfind("_") + 1:]
57 57
graph_types = {
58 58
    "accesses": [
59 59
        {
......
91 91

  
92 92

  
93 93
if len(sys.argv) == 2 and sys.argv[1] == "autoconf":
94
    print "yes"
94
    print("yes")
95 95
elif len(sys.argv) == 2 and sys.argv[1] == "config":
96 96
    if graph_type not in graph_types.keys():
97 97
        raise Exception("Unknown graph type '%s'" % graph_type)
98 98
    params = graph_types[graph_type]
99 99
    for item in params:
100
        print "graph_title %s" % item["title"]
101
        print "graph_category webserver"
100
        print("graph_title %s" % item["title"])
101
        print("graph_category webserver")
102 102
        for field in item["fields"]:
103
            print "%s.label %s" % (field, field)
104
            print "%s.type %s" % (field, item["type"])
105
        print "graph_args %s" % item["args"]
103
            print("%s.label %s" % (field, field))
104
            print("%s.type %s" % (field, item["type"]))
105
        print("graph_args %s" % item["args"])
106 106
elif len(sys.argv) == 2 and sys.argv[1] == "suggest":
107 107
    for item in graph_types.keys():
108
        print item
108
        print(item)
109 109
else:
110 110
    status_url = os.environ.get('status_url', 'http://127.0.0.1/server-status')
111 111

  
......
129 129
            pass
130 130

  
131 131
    if graph_type == "accesses":
132
        print "accesses.value %s" % data["Total Accesses"]
132
        print("accesses.value %s" % data["Total Accesses"])
133 133
    elif graph_type == "kbytes":
134
        print "kbytes.value %s" % data["Total kBytes"]
134
        print("kbytes.value %s" % data["Total kBytes"])
135 135
    elif graph_type == "uptime":
136
        print "uptime.value %s" % str(float(data["Uptime"])/86400)
136
        print("uptime.value %s" % str(float(data["Uptime"]) / 86400))
137 137
    elif graph_type == "status":
138
        print "busy.value %s" % data["BusyServers"]
139
        print "idle.value %s" % data["IdleServers"]
138
        print("busy.value %s" % data["BusyServers"])
139
        print("idle.value %s" % data["IdleServers"])
plugins/nginx/nginx_upstream_multi_
54 54

  
55 55
# How we've been called
56 56
progName = sys.argv[0]
57
progName = progName[progName.rfind("/")+1:]
57
progName = progName[progName.rfind("/") + 1:]
58 58

  
59 59

  
60 60
# Where to store plugin state
plugins/percona/percona_
53 53
program_name = os.path.basename(__file__)
54 54

  
55 55
variables = {
56
  'percona_queues': {
57
    'label': 'Queue sizes',
58
    'vlabel': 'size',
59
    'fields': ['wsrep_local_recv_queue', 'wsrep_local_send_queue']
60
  },
61
  'percona_flow': {
62
    'label': 'Flow control',
63
    'vlabel': '',
64
    'fields': ['wsrep_flow_control_sent', 'wsrep_flow_control_recv']
65
  },
66
  'percona_transactions': {
67
    'label': 'Transactions in and out',
68
    'vlabel': 'transactions',
69
    'fields': ['wsrep_replicated', 'wsrep_received']
70
  },
71
  'percona_transactions_bytes': {
72
    'label': 'Transactions in and out in bytes',
73
    'vlabel': 'bytes',
74
    'fields': ['wsrep_replicated_bytes', 'wsrep_received_bytes']
75
  },
76
  'percona_replication': {
77
    'label': 'Replication conflicts',
78
    'vlabel': 'conflicts',
79
    'fields': ['wsrep_local_cert_failures', 'wsrep_local_bf_aborts'],
80
  }
56
    'percona_queues': {
57
        'label': 'Queue sizes',
58
        'vlabel': 'size',
59
        'fields': ['wsrep_local_recv_queue', 'wsrep_local_send_queue']
60
    },
61
    'percona_flow': {
62
        'label': 'Flow control',
63
        'vlabel': '',
64
        'fields': ['wsrep_flow_control_sent', 'wsrep_flow_control_recv']
65
    },
66
    'percona_transactions': {
67
        'label': 'Transactions in and out',
68
        'vlabel': 'transactions',
69
        'fields': ['wsrep_replicated', 'wsrep_received']
70
    },
71
    'percona_transactions_bytes': {
72
        'label': 'Transactions in and out in bytes',
73
        'vlabel': 'bytes',
74
        'fields': ['wsrep_replicated_bytes', 'wsrep_received_bytes']
75
    },
76
    'percona_replication': {
77
        'label': 'Replication conflicts',
78
        'vlabel': 'conflicts',
79
        'fields': ['wsrep_local_cert_failures', 'wsrep_local_bf_aborts'],
80
    }
81 81
}
82 82

  
83 83
# Parse environment variables
plugins/prosody/prosody_
139 139
            telnet.write("server:uptime()\n")
140 140
            telnet_response = telnet.read_until("minutes (", 5)
141 141
            parsed_info = uptime_re.findall(telnet_response)
142
            uptime_value = (float(parsed_info[0]) + float(parsed_info[1])/24
143
                            + float(parsed_info[2])/60/24)
142
            uptime_value = (float(parsed_info[0]) + float(parsed_info[1]) / 24
143
                            + float(parsed_info[2]) / 60 / 24)
144 144
            print("uptime.value %s" % (uptime_value))
145 145
            telnet.write("quit\n")
146 146

  
plugins/router/arris-tg3442
102 102
        bytes(password.encode("ascii")),
103 103
        salt,
104 104
        iterations=1000,
105
        dklen=128/8
105
        dklen=128 / 8
106 106
    )
107 107
    secret = {"Password": password, "Nonce": current_session_id}
108 108
    plaintext = bytes(json.dumps(secret).encode("ascii"))
plugins/router/technicolor_tc8715d
197 197
    """multigraph technicolor_tc8715d_snr
198 198
graph_title Technicolor TC8715D Cable Modem SNR
199 199
graph_vlabel Signal-to-Noise Ratio (dB)
200
graph_info This graph shows the downstream signal-to-noise ratio reported by a Technicolor TC8715D cable modem.
200
graph_info Downstream signal-to-noise ratio reported by a Technicolor TC8715D cable modem.
201 201
graph_category network"""
202 202
)
203 203

  
......
212 212
    """multigraph technicolor_tc8715d_codewords
213 213
graph_title Technicolor TC8715D Cable Modem Codewords
214 214
graph_vlabel Codewords/${graph_period}
215
graph_info This graph shows the downstream codeword rates reported by a Technicolor TC8715D cable modem.
215
graph_info Downstream codeword rates reported by a Technicolor TC8715D cable modem.
216 216
graph_category network"""
217 217
)
218 218

  
plugins/solr/solr4_
77 77
        data = params['core'].rsplit('_', 1)
78 78
        handler = data.pop()
79 79
        params['params'] = {
80
                'handler': os.environ.get('qpshandler_%s' % handler, 'standard')
80
            'handler': os.environ.get('qpshandler_%s' % handler, 'standard'),
81 81
        }
82 82
        if not data:
83 83
            params['core'] = ''
......
416 416
            handler=self.params['params']['handler'],
417 417
            core=self.params['core'],
418 418
            cores_qps_cdefs='%s,%s' % (','.join(map(lambda x: 'qps_%s' % x, cores)),
419
                                       ','.join(['+'] * (len(cores)-1))),
419
                                       ','.join(['+'] * (len(cores) - 1))),
420 420
            gorder=','.join(cores)
421 421
        )
422 422

  
......
512 512
        SOLR_URL = '/' + SOLR_URL
513 513
    mb = SolrMuninGraph(SOLR_HOST_PORT, SOLR_URL, params)
514 514
    if hasattr(mb, params['op']):
515
        print(getattr(mb,  params['op'])(params['type']))
515
        print(getattr(mb, params['op'])(params['type']))
plugins/sphinx/sphindex_
42 42

  
43 43

  
44 44
prog_name = sys.argv[0]
45
index_name = prog_name[prog_name.find("_")+1:]
45
index_name = prog_name[prog_name.find("_") + 1:]
46 46

  
47 47
if len(sys.argv) == 2 and sys.argv[1] == "autoconf":
48 48
    print("yes")
plugins/synology/snmp__synology
91 91
                if not oid.startswith(disk_table):
92 92
                    continue
93 93

  
94
                disk_id = oid[oid.rindex('.')+1:]
94
                disk_id = oid[oid.rindex('.') + 1:]
95 95

  
96 96
                values = devices.get(disk_id, [None, None, None])
97 97
                if oid.startswith(disktable_id):
......
119 119
        return int(varBindTable[0][1])
120 120

  
121 121
    def print_config(self):
122
        print """multigraph synology_hdd_temperatures
122
        print("""multigraph synology_hdd_temperatures
123 123
host_name {hostname}
124 124
graph_title HDD temperatures on {hostname}
125 125
graph_vlabel Temperature in °C
126 126
graph_args --base 1000
127 127
graph_category sensors
128
graph_info HDD temperatures on {hostname}""".format(hostname=self.hostname)
128
graph_info HDD temperatures on {hostname}""".format(hostname=self.hostname))
129 129

  
130 130
        for id, name, model, temp in self._get_disks():
131
            print """disk{disk_id}.info Temperature of {name} ({model})
131
            print("""disk{disk_id}.info Temperature of {name} ({model})
132 132
disk{disk_id}.label {name} ({model})
133 133
disk{disk_id}.type GAUGE
134
disk{disk_id}.min 0""".format(disk_id=id, name=name, model=model)
134
disk{disk_id}.min 0""".format(disk_id=id, name=name, model=model))
135 135

  
136
        print """multigraph synology_sys_temperature
136
        print("""multigraph synology_sys_temperature
137 137
host_name {hostname}
138 138
graph_title System temperatures of {hostname}
139 139
graph_vlabel Temperature in °C
......
144 144
sys_temp.label Temperature
145 145
sys_temp.type GAUGE
146 146
sys_temp.min 0
147
""".format(hostname=self.hostname)
147
""".format(hostname=self.hostname))
148 148

  
149 149
    def execute(self):
150
        print """multigraph synology_hdd_temperatures"""
150
        print("""multigraph synology_hdd_temperatures""")
151 151
        for id, name, model, temp in self._get_disks():
152
            print """disk{disk_id}.value {temp}""".format(disk_id=id, temp=temp)
152
            print("""disk{disk_id}.value {temp}""".format(disk_id=id, temp=temp))
153 153

  
154
        print """multigraph synology_sys_temperature"""
155
        print "sys_temp.value {temp}".format(temp=self._get_sys_temperature())
154
        print("""multigraph synology_sys_temperature""")
155
        print("sys_temp.value {temp}".format(temp=self._get_sys_temperature()))
156 156

  
157 157

  
158 158
host = None
......
175 175

  
176 176

  
177 177
if "snmpconf" in sys.argv[1:]:
178
    print "require 1.3.6.1.4.1.6574.2.1.1"
178
    print("require 1.3.6.1.4.1.6574.2.1.1")
179 179
    sys.exit(0)
180 180
else:
181 181
    if not (host and port and community):
plugins/torrent/deluge_
121 121
log.setLevel(logging.WARNING)
122 122

  
123 123
conf = {
124
    'host':       os.getenv('host', '127.0.0.1'),
125
    'port':       int(os.getenv('port', '58846')),
126
    'username':   os.getenv('username', ''),
127
    'password':   os.getenv('password', '')
124
    'host': os.getenv('host', '127.0.0.1'),
125
    'port': int(os.getenv('port', '58846')),
126
    'username': os.getenv('username', ''),
127
    'password': os.getenv('password', '')
128 128
}
129 129

  
130 130
names_for_munin = {
131
    'numConnections':        'numConnections',
132
    'payloadUploadRate':     'payloadUploadRate',
133
    'overheadUploadRate':    'overheadUploadRate',
134
    'payloadDownloadRate':   'payloadDownloadRate',
135
    'overheadDownloadRate':  'overheadDownloadRate',
136
    'state.Seeding':         'seeding',
137
    'state.Downloading':     'downloading',
138
    'state.Paused':          'paused',
139
    'state.Error':           'error',
140
    'state.Queued':          'queued',
141
    'state.Checking':        'checking',
142
    'state.Other':           'other'
131
    'numConnections': 'numConnections',
132
    'payloadUploadRate': 'payloadUploadRate',
133
    'overheadUploadRate': 'overheadUploadRate',
134
    'payloadDownloadRate': 'payloadDownloadRate',
135
    'overheadDownloadRate': 'overheadDownloadRate',
136
    'state.Seeding': 'seeding',
137
    'state.Downloading': 'downloading',
138
    'state.Paused': 'paused',
139
    'state.Error': 'error',
140
    'state.Queued': 'queued',
141
    'state.Checking': 'checking',
142
    'state.Other': 'other'
143 143
}
144 144

  
145 145
torrent_states = ["Downloading",
......
300 300
            "graph_info This graph shows the number of connections used by Deluge Torrent")
301 301
        print(names_for_munin["numConnections"] + ".label connections")
302 302
        print(names_for_munin["numConnections"] + ".min 0")
303
        print(names_for_munin["numConnections"] +
304
              ".info The number of connections used by Deluge Torrent")
303
        print(names_for_munin["numConnections"]
304
              + ".info The number of connections used by Deluge Torrent")
305 305
    elif mode == "bandwidth":
306 306
        print("graph_title Bandwidth usage")
307 307
        print("graph_order payloadDownloadRate overheadDownloadRate payloadUploadRate "
......
353 353
        print("graph_period second")
354 354

  
355 355
        for state_name in torrent_states:
356
            print(names_for_munin["state." +
357
                                  state_name] + ".label " + state_name)
356
            print(names_for_munin["state." + state_name] + ".label " + state_name)
358 357
            print(names_for_munin["state." + state_name] + ".draw AREASTACK")
359 358
            print(names_for_munin["state." + state_name] + ".type GAUGE")
360 359
            print(names_for_munin["state." + state_name] + ".min 0")
361
            print(names_for_munin["state." + state_name] +
362
                  ".info Number of torrents in the '" + state_name + "' state")
360
            print(names_for_munin["state." + state_name]
361
                  + ".info Number of torrents in the '" + state_name + "' state")
363 362

  
364 363

  
365 364
def fetch_info(mode):
plugins/weather/weather_
3 3
import os
4 4
import re
5 5
import sys
6
import urllib
6
from urllib.request import urlopen
7 7

  
8 8
url = 'http://www.weather.com/weather/today/%s'
9 9

  
......
19 19
elif len(sys.argv) == 2 and sys.argv[1] == "autoconf":
20 20
    print("yes")
21 21
elif len(sys.argv) == 2 and sys.argv[1] == "config":
22
    u = urllib.urlopen(url % code)
22
    u = urlopen(url % code)
23 23
    txt = u.read()
24 24
    u.close()
25 25

  
......
39 39

  
40 40
    print('graph_args --base 1000 -l 0')
41 41
else:
42
    u = urllib.urlopen(url % code)
42
    u = urlopen(url % code)
43 43
    txt = u.read()
44 44
    u.close()
45 45

  
......
53 53

  
54 54
    if len(TMP_F_list):
55 55
        TMP_F = TMP_F_list[0]
56
        TMP_C = (int(TMP_F) - 32) * 5/9
56
        TMP_C = (int(TMP_F) - 32) * 5 / 9
57 57
    else:
58 58
        sys.exit(1)
59 59

  
plugins/weather/weather_press_
21 21
re_hpa = re.compile(r'Pressure.*\((\d+) hPa\)')
22 22

  
23 23

  
24
code = sys.argv[0][(sys.argv[0].rfind('_')+1):]
24
code = sys.argv[0][(sys.argv[0].rfind('_') + 1):]
25 25
if not code:
26 26
    sys.exit(1)
27 27
elif len(sys.argv) == 2 and sys.argv[1] == "autoconf":
plugins/weather/weather_temp_
21 21
re_C = re.compile(r'Temperature:.*\((-?\d+\.?\d?) C\)')
22 22
re_DewC = re.compile(r'Dew.*\((-?\d+\.?\d?) C\)')
23 23

  
24
code = sys.argv[0][(sys.argv[0].rfind('_')+1):]
24
code = sys.argv[0][(sys.argv[0].rfind('_') + 1):]
25 25

  
26 26

  
27 27
if not code:

Formats disponibles : Unified diff