From 486dad25baa48d6e243e47c3c53219d928fcf80f Mon Sep 17 00:00:00 2001 From: Bryan Irvine Date: Mon, 17 Jul 2023 15:47:22 -0500 Subject: [PATCH] python3 testing --- check_graphite.py | 18 ++++++------- cisco-airespace.py | 14 +++++----- codahale_metrics.py | 44 ++++++++++++++++---------------- emcisilon_disk_perf_stats.py | 14 +++++----- emcisilon_fan_speed.py | 14 +++++----- emcisilon_powersensor.py | 14 +++++----- emcisilon_protocol_perf_stats.py | 14 +++++----- emcisilon_quota.py | 14 +++++----- emcisilon_snapshot.py | 14 +++++----- emcisilon_tempsensor.py | 14 +++++----- graphite_snmp.py | 2 +- gtm_dns_stats.py | 14 +++++----- gtm_wideip_stats.py | 14 +++++----- haproxy_backend_stats.py | 14 +++++----- haproxy_frontend_stats.py | 14 +++++----- haproxy_server_stats.py | 14 +++++----- infoblox_dhcp_stats.py | 14 +++++----- infoblox_zone_stats.py | 14 +++++----- interface_stats.py | 20 +++++++-------- ltm_interface_stats.py | 14 +++++----- ltm_virtualserver_stats.py | 14 +++++----- ltm_vlan_stats.py | 14 +++++----- nutanix-cit-stats.py | 14 +++++----- nutanix-cluster-stats.py | 14 +++++----- nutanix-dst-stats.py | 14 +++++----- nutanix-spit-stats.py | 14 +++++----- pickledump.py | 2 +- snmp_pickle.py | 16 ++++++------ synology_disk_stats.py | 14 +++++----- synology_spaceio_stats.py | 14 +++++----- synology_storageio_stats.py | 14 +++++----- 31 files changed, 226 insertions(+), 226 deletions(-) diff --git a/check_graphite.py b/check_graphite.py index 3b0ca6d..2912a3d 100644 --- a/check_graphite.py +++ b/check_graphite.py @@ -2,7 +2,7 @@ import sys import json -from httplib import HTTPConnection +from http.client import HTTPConnection from optparse import OptionParser @@ -15,15 +15,15 @@ def fetchMetrics(host, port, url): try: data = response.read() except Exception as uhoh: - print "unknown error, possible empty response?: %s" % uhoh + print("unknown error, possible empty response?: %s" % uhoh) elif response.status == 401: - print "Invalid username or password." + print("Invalid username or password.") sys.exit(1) elif response.status == 404: - print "Web service not found." + print("Web service not found.") sys.exit(1) else: - print "Web service error (%d): %s" % (response.status, response.reason) + print("Web service error (%d): %s" % (response.status, response.reason)) sys.exit(1) return data @@ -35,7 +35,7 @@ def processResponse(body, nulls): # for metric, timestamp in data[0]['datapoints']: # return metric if not data: - print "no data returned" + print("no data returned") sys.exit(1) for metric, timestamp in data[0]['datapoints']: if nulls and not metric: @@ -98,7 +98,7 @@ def makeNagios(metric, warning, critical): max = cend else: critical = '' - print "%s - %s|%s=%s;%s;%s;%s;%s; " % (severity, carbonCache, carbonCache, metric, warning, critical, min, max ) + print("%s - %s|%s=%s;%s;%s;%s;%s; " % (severity, carbonCache, carbonCache, metric, warning, critical, min, max )) sys.exit(code) @@ -126,10 +126,10 @@ def main(): options, args = parser.parse_args() if not options.host: - print >> sys.stderr, "You must specify the host." + print("You must specify the host.", file=sys.stderr) sys.exit(1) elif not options.url: - print >> sys.stderr, "You must specify the url." + print("You must specify the url.", file=sys.stderr) sys.exit(1) global carbonCache diff --git a/cisco-airespace.py b/cisco-airespace.py index 36e79c1..f64afca 100644 --- a/cisco-airespace.py +++ b/cisco-airespace.py @@ -19,7 +19,7 @@ def fetchOID(host, community, graphiteroot, interface, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'sysInterfaceStatPktsIn': '1.3.6.1.4.1.3375.2.1.2.4.4.3.1.2', @@ -62,12 +62,12 @@ def fetchOID(host, community, graphiteroot, interface, verbose): result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (vs.val, type, result) + print('%s %s = %s' % (vs.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, vs.val.replace('.', '-'), type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -75,7 +75,7 @@ def fetchOID(host, community, graphiteroot, interface, verbose): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -85,16 +85,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/codahale_metrics.py b/codahale_metrics.py index 6c76443..135c23c 100644 --- a/codahale_metrics.py +++ b/codahale_metrics.py @@ -14,7 +14,7 @@ import sys from base64 import b64encode from optparse import OptionParser -import urllib2, httplib +import urllib.request, urllib.error, urllib.parse, http.client import json socket.setdefaulttimeout(30.0) @@ -23,17 +23,17 @@ def processResponse(data,graphiteRoot,pickleport): timestamp = time.time() output = ([]) - if options.verbose: print >> sys.stderr, data + if options.verbose: print(data, file=sys.stderr) d = json.loads(data) try: # Step through JSON objects and sub objects and sub objects. - for everyone, two in d.iteritems(): + for everyone, two in d.items(): if type(two).__name__=='dict': - for attr, value in two.items(): + for attr, value in list(two.items()): if type(value).__name__=='dict': try: - for left, right in value.items(): + for left, right in list(value.items()): if not ((type(right).__name__ == "float") or (type(right).__name__ == "int")): continue # strip unicode stuff if '.' in everyone: @@ -60,7 +60,7 @@ def processResponse(data,graphiteRoot,pickleport): output.append((blah, (timestamp,two))) # probably not needed any longer except KeyError: - print >> sys.stderr, "Critical: Key not found: %s" % resource + print("Critical: Key not found: %s" % resource, file=sys.stderr) sys.exit(1) finally: @@ -82,9 +82,9 @@ def processResponse(data,graphiteRoot,pickleport): sys.exit(0) -class HTTPSClientAuthHandler(urllib2.HTTPSHandler): +class HTTPSClientAuthHandler(urllib.request.HTTPSHandler): def __init__(self, key, cert): - urllib2.HTTPSHandler.__init__(self) + urllib.request.HTTPSHandler.__init__(self) self.key = key self.cert = cert @@ -92,7 +92,7 @@ def https_open(self, req): return self.do_open(self.getConnection, req) def getConnection(self, host, timeout=300): - return httplib.HTTPSConnection(host, key_file=self.key, cert_file=self.cert) + return http.client.HTTPSConnection(host, key_file=self.key, cert_file=self.cert) if __name__ == '__main__': @@ -132,11 +132,11 @@ def getConnection(self, host, timeout=300): options, args = parser.parse_args() if not options.host: - print >> sys.stderr, "Critical: You must specify the host." + print("Critical: You must specify the host.", file=sys.stderr) sys.exit(1) if not options.url: - print >> sys.stderr, "You must specify a URL." + print("You must specify a URL.", file=sys.stderr) sys.exit(1) else: url = options.url @@ -153,30 +153,30 @@ def getConnection(self, host, timeout=300): # default to use SSL if the port is 443 if options.usingssl or options.port == '443': if not options.key: - from httplib import HTTPSConnection + from http.client import HTTPSConnection try: connection = HTTPSConnection(options.host, options.port) connection.request("GET", url, None, headers) except: - print >> sys.stderr, "Unable to make HTTPS connection to https://%s:%s%s" % ( options.host, options.port, url ) + print("Unable to make HTTPS connection to https://%s:%s%s" % ( options.host, options.port, url ), file=sys.stderr) sys.exit(1) else: - import urllib2 - from httplib import HTTPSConnection - opener = urllib2.build_opener(HTTPSClientAuthHandler(options.key, options.client)) + import urllib.request, urllib.error, urllib.parse + from http.client import HTTPSConnection + opener = urllib.request.build_opener(HTTPSClientAuthHandler(options.key, options.client)) connectString = "https://%s:%s%s" % (options.host, options.port, options.url) try: response = opener.open(connectString) except: - print >> sys.stderr, "Could not connect to %s" % connectString + print("Could not connect to %s" % connectString, file=sys.stderr) sys.exit(2) else: - from httplib import HTTPConnection + from http.client import HTTPConnection try: connection = HTTPConnection(options.host, options.port) connection.request("GET", url, None, headers) except Exception as e: - print >> sys.stderr, "Unable to make HTTP connection to http://%s:%s%s because: %s" % ( options.host, options.port, url, e ) + print("Unable to make HTTP connection to http://%s:%s%s because: %s" % ( options.host, options.port, url, e ), file=sys.stderr) sys.exit(1) graphiteRoot = "%s.%s" % ( options.graphiteRoot, options.host ) @@ -189,11 +189,11 @@ def getConnection(self, host, timeout=300): if returnCode == 200: processResponse(response.read(),graphiteRoot,options.pickleport) elif returnCode == 401: - print "Invalid username or password." + print("Invalid username or password.") sys.exit(1) elif returnCode == 404: - print "404 not found." + print("404 not found.") sys.exit(1) else: - print "Web service error %: " % returnCode #, (None if not response.reason else response.reason) ) + print("Web service error %: " % returnCode) #, (None if not response.reason else response.reason) ) sys.exit(1) diff --git a/emcisilon_disk_perf_stats.py b/emcisilon_disk_perf_stats.py index 20f2622..0c4776b 100644 --- a/emcisilon_disk_perf_stats.py +++ b/emcisilon_disk_perf_stats.py @@ -19,7 +19,7 @@ def fetchOID(host, community, graphiteroot, emcDisk, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'diskperfOpsPerSecond': '1.3.6.1.4.1.12124.2.2.52.1.3', @@ -55,12 +55,12 @@ def fetchOID(host, community, graphiteroot, emcDisk, verbose): result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (vs.val, type, result) + print('%s %s = %s' % (vs.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, vs.val.replace(' ',''), type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -68,7 +68,7 @@ def fetchOID(host, community, graphiteroot, emcDisk, verbose): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -78,16 +78,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/emcisilon_fan_speed.py b/emcisilon_fan_speed.py index 0d5d055..ec1a433 100644 --- a/emcisilon_fan_speed.py +++ b/emcisilon_fan_speed.py @@ -19,7 +19,7 @@ def fetchOID(host, community, graphiteroot, emcFan, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'fanSpeed': '1.3.6.1.4.1.12124.2.53.1.4' @@ -53,12 +53,12 @@ def fetchOID(host, community, graphiteroot, emcFan, verbose): result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (vs.val, type, result) + print('%s %s = %s' % (vs.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, vs.val.replace(' ',''), type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -66,7 +66,7 @@ def fetchOID(host, community, graphiteroot, emcFan, verbose): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -76,16 +76,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/emcisilon_powersensor.py b/emcisilon_powersensor.py index e12101a..2f4b760 100644 --- a/emcisilon_powersensor.py +++ b/emcisilon_powersensor.py @@ -19,7 +19,7 @@ def fetchOID(host, community, graphiteroot, emcPowerSensor, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'powerSensorValue': '.1.3.6.1.4.1.12124.2.55.1.4' @@ -53,12 +53,12 @@ def fetchOID(host, community, graphiteroot, emcPowerSensor, verbose): result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (vs.val, type, result) + print('%s %s = %s' % (vs.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, vs.val.replace(' ',''), type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -66,7 +66,7 @@ def fetchOID(host, community, graphiteroot, emcPowerSensor, verbose): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -76,16 +76,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/emcisilon_protocol_perf_stats.py b/emcisilon_protocol_perf_stats.py index 73d3b3e..eb2d24e 100644 --- a/emcisilon_protocol_perf_stats.py +++ b/emcisilon_protocol_perf_stats.py @@ -19,7 +19,7 @@ def fetchOID(host, community, graphiteroot, emcProtocol, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'protocolOpCount': '1.3.6.1.4.1.12124.2.2.10.1.2', @@ -68,12 +68,12 @@ def fetchOID(host, community, graphiteroot, emcProtocol, verbose): result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (vs.val, type, result) + print('%s %s = %s' % (vs.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, vs.val.replace(' ',''), type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -81,7 +81,7 @@ def fetchOID(host, community, graphiteroot, emcProtocol, verbose): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -91,16 +91,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/emcisilon_quota.py b/emcisilon_quota.py index decb250..9b99d6d 100644 --- a/emcisilon_quota.py +++ b/emcisilon_quota.py @@ -19,7 +19,7 @@ def fetchOID(host, community, graphiteroot, emcQuota, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'quotaUsage': '.1.3.6.1.4.1.12124.1.12.1.1.13', @@ -54,12 +54,12 @@ def fetchOID(host, community, graphiteroot, emcQuota, verbose): result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (vs.val, type, result) + print('%s %s = %s' % (vs.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, vs.val.replace(' ',''), type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -67,7 +67,7 @@ def fetchOID(host, community, graphiteroot, emcQuota, verbose): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -77,16 +77,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/emcisilon_snapshot.py b/emcisilon_snapshot.py index 6030c72..50586eb 100644 --- a/emcisilon_snapshot.py +++ b/emcisilon_snapshot.py @@ -19,7 +19,7 @@ def fetchOID(host, community, graphiteroot, emcSnapshot, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'quotaUsage': '.1.3.6.1.4.1.12124.1.13.3.1.5' @@ -53,12 +53,12 @@ def fetchOID(host, community, graphiteroot, emcSnapshot, verbose): result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (vs.val, type, result) + print('%s %s = %s' % (vs.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, vs.val.replace(' ',''), type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -66,7 +66,7 @@ def fetchOID(host, community, graphiteroot, emcSnapshot, verbose): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -76,16 +76,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/emcisilon_tempsensor.py b/emcisilon_tempsensor.py index 1883b23..e0a2125 100644 --- a/emcisilon_tempsensor.py +++ b/emcisilon_tempsensor.py @@ -19,7 +19,7 @@ def fetchOID(host, community, graphiteroot, emcTempSensor, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'tempSensorValue': '.1.3.6.1.4.1.12124.2.54.1.4' @@ -53,12 +53,12 @@ def fetchOID(host, community, graphiteroot, emcTempSensor, verbose): result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (vs.val, type, result) + print('%s %s = %s' % (vs.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, vs.val.replace(' ',''), type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -66,7 +66,7 @@ def fetchOID(host, community, graphiteroot, emcTempSensor, verbose): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -76,16 +76,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/graphite_snmp.py b/graphite_snmp.py index a38fd23..73ab0e4 100755 --- a/graphite_snmp.py +++ b/graphite_snmp.py @@ -7,6 +7,6 @@ options, args = parser.parse_args() for i, opt in enumerate(options.test): - print 'option %s: %s' % (i, opt) + print('option %s: %s' % (i, opt)) diff --git a/gtm_dns_stats.py b/gtm_dns_stats.py index 38e2763..857d115 100755 --- a/gtm_dns_stats.py +++ b/gtm_dns_stats.py @@ -18,7 +18,7 @@ def fetchOID(host, community, graphiteroot, virtualserver, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'gtmPoolStatPreferred': '1.3.6.1.4.1.3375.2.3.6.2.3.1.2', @@ -55,12 +55,12 @@ def fetchOID(host, community, graphiteroot, virtualserver, verbose): result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (vs.val, type, result) + print('%s %s = %s' % (vs.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, vs.val, type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -68,7 +68,7 @@ def fetchOID(host, community, graphiteroot, virtualserver, verbose): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -78,16 +78,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/gtm_wideip_stats.py b/gtm_wideip_stats.py index cd1025f..c315723 100755 --- a/gtm_wideip_stats.py +++ b/gtm_wideip_stats.py @@ -18,7 +18,7 @@ def fetchOID(host, community, graphiteroot, virtualserver, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'gtmWideipStatRequests': '1.3.6.1.4.1.3375.2.3.12.2.3.1.2', @@ -58,12 +58,12 @@ def fetchOID(host, community, graphiteroot, virtualserver, verbose): result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (vs.val, type, result) + print('%s %s = %s' % (vs.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, vs.val, type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -71,7 +71,7 @@ def fetchOID(host, community, graphiteroot, virtualserver, verbose): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -81,16 +81,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/haproxy_backend_stats.py b/haproxy_backend_stats.py index 52084ad..24ee9c0 100644 --- a/haproxy_backend_stats.py +++ b/haproxy_backend_stats.py @@ -19,7 +19,7 @@ def fetchOID(host, community, graphiteroot, backend, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'bytesIn': '1.3.6.1.4.1.29385.106.1.1.8', @@ -66,12 +66,12 @@ def fetchOID(host, community, graphiteroot, backend, verbose): result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (vs.val, type, result) + print('%s %s = %s' % (vs.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, vs.val, type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -79,7 +79,7 @@ def fetchOID(host, community, graphiteroot, backend, verbose): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -89,16 +89,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/haproxy_frontend_stats.py b/haproxy_frontend_stats.py index 90eb06e..eb269b0 100644 --- a/haproxy_frontend_stats.py +++ b/haproxy_frontend_stats.py @@ -19,7 +19,7 @@ def fetchOID(host, community, graphiteroot, frontend, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'bytesIn': '1.3.6.1.4.1.29385.106.1.0.8', @@ -66,12 +66,12 @@ def fetchOID(host, community, graphiteroot, frontend, verbose): result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (vs.val, type, result) + print('%s %s = %s' % (vs.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, vs.val, type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -79,7 +79,7 @@ def fetchOID(host, community, graphiteroot, frontend, verbose): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -89,16 +89,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/haproxy_server_stats.py b/haproxy_server_stats.py index 61b0d49..8747025 100644 --- a/haproxy_server_stats.py +++ b/haproxy_server_stats.py @@ -19,7 +19,7 @@ def fetchOID(host, community, graphiteroot, haServer, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'bytesIn': '1.3.6.1.4.1.29385.106.1.2.8', @@ -64,12 +64,12 @@ def fetchOID(host, community, graphiteroot, haServer, verbose): result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (vs.val, type, result) + print('%s %s = %s' % (vs.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, vs.val, type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -77,7 +77,7 @@ def fetchOID(host, community, graphiteroot, haServer, verbose): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -87,16 +87,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/infoblox_dhcp_stats.py b/infoblox_dhcp_stats.py index 6801295..7772d34 100644 --- a/infoblox_dhcp_stats.py +++ b/infoblox_dhcp_stats.py @@ -19,7 +19,7 @@ def fetchOID(host, community, graphiteroot, zone, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'ibDHCPSubnetNetworkPercentUsed': '1.3.6.1.4.1.7779.3.1.1.4.1.1.1.3' @@ -59,12 +59,12 @@ def fetchOID(host, community, graphiteroot, zone, verbose): network = vs.val.replace('.', '-') + '-' + cidr(netmask) if verbose: - print >> sys.stderr, '%s %s = %s' % (network, type, result) + print('%s %s = %s' % (network, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, network, type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -74,7 +74,7 @@ def cidr(quad): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -84,16 +84,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/infoblox_zone_stats.py b/infoblox_zone_stats.py index a146f35..e8e5a6f 100644 --- a/infoblox_zone_stats.py +++ b/infoblox_zone_stats.py @@ -19,7 +19,7 @@ def fetchOID(host, community, graphiteroot, zone, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'ibBindZoneSuccess': '1.3.6.1.4.1.7779.3.1.1.3.1.1.1.2', @@ -57,12 +57,12 @@ def fetchOID(host, community, graphiteroot, zone, verbose): result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (vs.val, type, result) + print('%s %s = %s' % (vs.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, vs.val, type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -70,7 +70,7 @@ def fetchOID(host, community, graphiteroot, zone, verbose): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -80,16 +80,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/interface_stats.py b/interface_stats.py index 439ee75..72edf3f 100755 --- a/interface_stats.py +++ b/interface_stats.py @@ -14,7 +14,7 @@ def fetchOID(host, community, secLevel, secName, version, authProtocol, authPassword, privProtocol, privPassword, index, graphiteroot, verbose, debug): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) ifTable = { 'ifHCInOctets': '.1.3.6.1.2.1.31.1.1.1.6', @@ -33,7 +33,7 @@ def fetchOID(host, community, secLevel, secName, version, authProtocol, authPass snmp = netsnmp.Session(DestHost=host, Version=3, SecLevel=secLevel, AuthProto=authProtocol, AuthPass=authPassword, PrivProto=privProtocol, PrivPass=privPassword, SecName=secName) else: - print 'unknown version %s' % version + print('unknown version %s' % version) currentTime = time.time() if not index: @@ -50,12 +50,12 @@ def fetchOID(host, community, secLevel, secName, version, authProtocol, authPass result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s = %s' % (type, result) + print('%s = %s' % (type, result), file=sys.stderr) currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, vs.val, type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) sys.exit(1) else: @@ -65,18 +65,18 @@ def fetchOID(host, community, secLevel, secName, version, authProtocol, authPass result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s = %s' % (type, result) + print('%s = %s' % (type, result), file=sys.stderr) datapoint = '%s.%s' % (graphiteroot, type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) sys.exit(1) return package, currentTime, result def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) shippingPackage = pickle.dumps(package, 1) @@ -85,16 +85,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose, debug): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/ltm_interface_stats.py b/ltm_interface_stats.py index 2872f39..2a0ed0b 100644 --- a/ltm_interface_stats.py +++ b/ltm_interface_stats.py @@ -19,7 +19,7 @@ def fetchOID(host, community, graphiteroot, interface, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'sysInterfaceStatPktsIn': '1.3.6.1.4.1.3375.2.1.2.4.4.3.1.2', @@ -62,12 +62,12 @@ def fetchOID(host, community, graphiteroot, interface, verbose): result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (vs.val, type, result) + print('%s %s = %s' % (vs.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, vs.val.replace('.', '-'), type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -75,7 +75,7 @@ def fetchOID(host, community, graphiteroot, interface, verbose): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -85,16 +85,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/ltm_virtualserver_stats.py b/ltm_virtualserver_stats.py index 8928f6a..18c3f05 100755 --- a/ltm_virtualserver_stats.py +++ b/ltm_virtualserver_stats.py @@ -19,7 +19,7 @@ def fetchOID(host, community, graphiteroot, virtualserver, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'clientBytesIn': '1.3.6.1.4.1.3375.2.2.10.2.3.1.7', @@ -81,12 +81,12 @@ def fetchOID(host, community, graphiteroot, virtualserver, verbose): result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (vs.val, type, result) + print('%s %s = %s' % (vs.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, vs.val, type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -94,7 +94,7 @@ def fetchOID(host, community, graphiteroot, virtualserver, verbose): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -104,16 +104,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/ltm_vlan_stats.py b/ltm_vlan_stats.py index ac462b1..3db0de9 100644 --- a/ltm_vlan_stats.py +++ b/ltm_vlan_stats.py @@ -19,7 +19,7 @@ def fetchOID(host, community, graphiteroot, vlan, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'sysVlanStatPktsIn': '1.3.6.1.4.1.3375.2.1.2.13.6.2.1.2', @@ -68,12 +68,12 @@ def fetchOID(host, community, graphiteroot, vlan, verbose): result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (sysVlanVname, type, result) + print('%s %s = %s' % (sysVlanVname, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, sysVlanVname, type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -81,7 +81,7 @@ def fetchOID(host, community, graphiteroot, vlan, verbose): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -91,16 +91,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/nutanix-cit-stats.py b/nutanix-cit-stats.py index e88285e..fc3fcd8 100644 --- a/nutanix-cit-stats.py +++ b/nutanix-cit-stats.py @@ -20,7 +20,7 @@ def fetchOID(host, username, seclevel, authProto, authPass, privPass, privProto, graphiteroot, cit, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using username: %s' % ( host, username ) + print('connecting to host: %s using username: %s' % ( host, username ), file=sys.stderr) statsTable = { 'citTotalCapacity': '1.3.6.1.4.1.41263.8.1.4', @@ -62,12 +62,12 @@ def fetchOID(host, username, seclevel, result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (container.val, type, result) + print('%s %s = %s' % (container.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, citContainerId, type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -75,7 +75,7 @@ def fetchOID(host, username, seclevel, def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -85,16 +85,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/nutanix-cluster-stats.py b/nutanix-cluster-stats.py index 0e411b0..69fc51b 100644 --- a/nutanix-cluster-stats.py +++ b/nutanix-cluster-stats.py @@ -20,7 +20,7 @@ def fetchOID(host, username, seclevel, authProto, authPass, privPass, privProto, graphiteroot, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using username: %s' % ( host, username ) + print('connecting to host: %s using username: %s' % ( host, username ), file=sys.stderr) statsTable = { 'clusterName': '1.3.6.1.4.1.41263.501.0', @@ -52,12 +52,12 @@ def fetchOID(host, username, seclevel, else: result = float(x) if verbose: - print >> sys.stderr, '%s = %s' % (type, result) + print('%s = %s' % (type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, clusterName, type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -65,7 +65,7 @@ def fetchOID(host, username, seclevel, def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -75,16 +75,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/nutanix-dst-stats.py b/nutanix-dst-stats.py index 37840a3..f786697 100644 --- a/nutanix-dst-stats.py +++ b/nutanix-dst-stats.py @@ -20,7 +20,7 @@ def fetchOID(host, username, seclevel, authProto, authPass, privPass, privProto, graphiteroot, dst, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using username: %s' % ( host, username ) + print('connecting to host: %s using username: %s' % ( host, username ), file=sys.stderr) statsTable = { 'dstNumRawBytes': '1.3.6.1.4.1.41263.3.1.5', @@ -71,12 +71,12 @@ def fetchOID(host, username, seclevel, result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (disk.val, type, result) + print('%s %s = %s' % (disk.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s.%s' % (graphiteroot, dstDiskId, dstSerial, type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -84,7 +84,7 @@ def fetchOID(host, username, seclevel, def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -94,16 +94,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/nutanix-spit-stats.py b/nutanix-spit-stats.py index 702818e..738fc61 100644 --- a/nutanix-spit-stats.py +++ b/nutanix-spit-stats.py @@ -20,7 +20,7 @@ def fetchOID(host, username, seclevel, authProto, authPass, privPass, privProto, graphiteroot, spit, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using username: %s' % ( host, username ) + print('connecting to host: %s using username: %s' % ( host, username ), file=sys.stderr) statsTable = { 'spitTotalCapacity': '1.3.6.1.4.1.41263.7.1.4', @@ -61,12 +61,12 @@ def fetchOID(host, username, seclevel, result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (disk.val, type, result) + print('%s %s = %s' % (disk.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, spitStoragePoolName, type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -74,7 +74,7 @@ def fetchOID(host, username, seclevel, def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -84,16 +84,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/pickledump.py b/pickledump.py index e4150a4..2035f53 100644 --- a/pickledump.py +++ b/pickledump.py @@ -22,7 +22,7 @@ def main(): i = 0 while i < len(data): - print ("%s %s %s") % (data[i][0], data[i][1][1], data[i][1][0]) + print(("%s %s %s") % (data[i][0], data[i][1][1], data[i][1][0])) i = i + 1 if __name__ == '__main__': diff --git a/snmp_pickle.py b/snmp_pickle.py index 1315a80..c876b39 100755 --- a/snmp_pickle.py +++ b/snmp_pickle.py @@ -14,7 +14,7 @@ def fetchOID(host, community, oid, name): if options.verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) snmp = netsnmp.Session(DestHost=host, Version=2, Community=community) count = 0 while count < len(oid): @@ -24,20 +24,20 @@ def fetchOID(host, community, oid, name): result = [x[0] for x in snmp.get(vars)] result = float(x) if options.verbose: - print >> sys.stderr, '%s = %s' % (oid[count], result) + print('%s = %s' % (oid[count], result), file=sys.stderr) currentTime = time.time() datapoint = '%s.%s' % (options.graphiteroot, name[count]) package.append((datapoint, (currentTime, result))) count += 1 except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) sys.exit(1) makePickle(package, currentTime, result) def makePickle(datapoint, currentTime, data): if options.debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) shippingPackage = pickle.dumps(package, 1) @@ -46,16 +46,16 @@ def makePickle(datapoint, currentTime, data): def sendPickle(carbonServer, carbonPort, shippingPackage): packageSize = struct.pack('!L', len(shippingPackage)) if options.verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if options.verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) if __name__ == '__main__': @@ -92,7 +92,7 @@ def sendPickle(carbonServer, carbonPort, shippingPackage): # sys.exit() if len(options.oid) != len(options.name): - print >> sys.stderr, "Critical: you must 'name' each 'oid'" + print("Critical: you must 'name' each 'oid'", file=sys.stderr) sys.exit(1) fetchOID(options.host, options.community, options.oid, options.name) diff --git a/synology_disk_stats.py b/synology_disk_stats.py index cc68547..2fa6dbb 100755 --- a/synology_disk_stats.py +++ b/synology_disk_stats.py @@ -18,7 +18,7 @@ def fetchOID(host, community, graphiteroot, diskio, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'diskTemperature': '1.3.6.1.4.1.6574.2.1.1.6' @@ -50,12 +50,12 @@ def fetchOID(host, community, graphiteroot, diskio, verbose): result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (disk.val, type, result) + print('%s %s = %s' % (disk.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, disk.val, type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -63,7 +63,7 @@ def fetchOID(host, community, graphiteroot, diskio, verbose): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -73,16 +73,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/synology_spaceio_stats.py b/synology_spaceio_stats.py index e7fbf93..bb43430 100755 --- a/synology_spaceio_stats.py +++ b/synology_spaceio_stats.py @@ -18,7 +18,7 @@ def fetchOID(host, community, graphiteroot, diskio, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'spaceIONRead': '1.3.6.1.4.1.6574.102.1.1.3', @@ -59,12 +59,12 @@ def fetchOID(host, community, graphiteroot, diskio, verbose): result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (disk.val, type, result) + print('%s %s = %s' % (disk.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, disk.val, type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -72,7 +72,7 @@ def fetchOID(host, community, graphiteroot, diskio, verbose): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -82,16 +82,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main(): diff --git a/synology_storageio_stats.py b/synology_storageio_stats.py index 7f15600..808a45e 100755 --- a/synology_storageio_stats.py +++ b/synology_storageio_stats.py @@ -18,7 +18,7 @@ def fetchOID(host, community, graphiteroot, diskio, verbose): if verbose: - print >> sys.stderr, 'connecting to host: %s using community: %s' % ( host, community ) + print('connecting to host: %s using community: %s' % ( host, community ), file=sys.stderr) statsTable = { 'storageIONRead': '1.3.6.1.4.1.6574.101.1.1.3', @@ -59,12 +59,12 @@ def fetchOID(host, community, graphiteroot, diskio, verbose): result = [x[0] for x in snmp.get(vars)] result = float(x) if verbose: - print >> sys.stderr, '%s %s = %s' % (disk.val, type, result) + print('%s %s = %s' % (disk.val, type, result), file=sys.stderr) #currentTime = time.time() datapoint = '%s.%s.%s' % (graphiteroot, disk.val, type) package.append((datapoint, (currentTime, result))) except Exception as uhoh: - print >> sys.stderr, "could not get oid: %s" % uhoh + print("could not get oid: %s" % uhoh, file=sys.stderr) #sys.exit(1) return package, currentTime, result @@ -72,7 +72,7 @@ def fetchOID(host, community, graphiteroot, diskio, verbose): def makePickle(datapoint, currentTime, data, verbose, debug): if debug: - print >> sys.stderr, 'storing pickle in \'data.p\'' + print('storing pickle in \'data.p\'', file=sys.stderr) fh = open('data.p', 'wb') pickle.dump(package, fh) sys.exit() @@ -82,16 +82,16 @@ def makePickle(datapoint, currentTime, data, verbose, debug): def sendPickle(carbonServer, carbonPort, shippingPackage, verbose): packageSize = struct.pack('!L', len(shippingPackage)) if verbose: - print >> sys.stderr, 'connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ) + print('connecting to carbon server: %s on port: %s' % ( carbonServer, carbonPort ), file=sys.stderr) try: s = socket.socket() s.connect((carbonServer, carbonPort)) s.sendall(packageSize) s.sendall(shippingPackage) if verbose: - print >> sys.stderr, 'sending pickle...' + print('sending pickle...', file=sys.stderr) except Exception as uhoh: - print "Could not connect to carbon server: %s" % uhoh + print("Could not connect to carbon server: %s" % uhoh) sys.exit(1) def main():