Skip to content
Permalink
Browse files

Python 3: Fixed py2 print statements in all remaining files

Change-Id: Ia2bec4963164138009a994c77a323eea2dba5403
  • Loading branch information...
loocars committed Jul 30, 2019
1 parent f9137b6 commit e9154bdb738ba52d445c6d13d1cb8c0653013ff3
@@ -1,3 +1,4 @@
from __future__ import print_function
import pytest
import os
import subprocess
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8; py-indent-offset: 4 -*-
from __future__ import print_function
import configparser
import yaml
from contextlib import contextmanager
@@ -24,6 +24,7 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
"""Modes for services and discovery"""
from __future__ import print_function

import ast
import os
@@ -432,7 +433,7 @@ def __init__(self, host_name):
def discover(self, request, job_interface):
# type: (StartDiscoveryRequest, BackgroundProcessInterface) -> None
"""Target function of the background job"""
print "Starting job..."
print("Starting job...")
if request.options.action == DiscoveryAction.SCAN:
self._jobstatus.update_status({"title": _("Full scan")})
self._perform_service_scan(request)
@@ -443,7 +444,7 @@ def discover(self, request, job_interface):

else:
raise NotImplementedError()
print "Completed."
print("Completed.")

def _perform_service_scan(self, request):
"""The try-inventory automation refreshes the Check_MK internal cache and makes the new
@@ -24,6 +24,7 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
"""Place for common code shared among different Check_MK special agents"""
from __future__ import print_function

import abc
import datetime
@@ -98,7 +99,7 @@ def get_content(self):
try:
pprint.pprint(json.loads(line))
except Exception:
print line
print(line)
else:
return content

@@ -61,6 +61,7 @@
user/group and permissions could leave the backup file more readable that
you'd prefer. You can always use the --nobackup option to prevent this.
"""
from __future__ import print_function

__version__ = "1"

@@ -76,8 +77,8 @@

def usage(msg=None):
if msg is not None:
print >> sys.stderr, msg
print >> sys.stderr, __doc__
print(msg, file=sys.stderr)
print(__doc__, file=sys.stderr)


def errprint(*args):
@@ -121,7 +122,7 @@ def main():
def check(file):
if os.path.isdir(file) and not os.path.islink(file):
if verbose:
print "listing directory", file
print("listing directory", file)
names = os.listdir(file)
for name in names:
fullname = os.path.join(file, name)
@@ -131,7 +132,7 @@ def check(file):
return

if verbose:
print "checking", file, "...",
print("checking", file, "...", end=' ')
try:
f = open(file)
except IOError as msg:
@@ -142,24 +143,24 @@ def check(file):
f.close()
if r.run():
if verbose:
print "changed."
print("changed.")
if dryrun:
print "But this is a dry run, so leaving it alone."
print("But this is a dry run, so leaving it alone.")
if not dryrun:
bak = file + ".bak"
if makebackup:
shutil.copyfile(file, bak)
if verbose:
print "backed up", file, "to", bak
print("backed up", file, "to", bak)
f = open(file, "w")
r.write(f)
f.close()
if verbose:
print "wrote new", file
print("wrote new", file)
return True
else:
if verbose:
print "unchanged."
print("unchanged.")
return False


@@ -1,6 +1,7 @@
#!/usr/bin/python
# Example program for accessing status of event console

from __future__ import print_function
import socket, os

# Create Unix socket and connect to status socket
@@ -28,5 +29,5 @@ for row in response[1:]:
with_headers = sorted(zip(headers, row))

for key, value in with_headers:
print "%-20s: %s" % (key, value)
print
print("%-20s: %s" % (key, value))
print()
@@ -24,6 +24,7 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.

from __future__ import print_function
import os, sys
import livestatus

@@ -38,33 +39,33 @@

try:
# Make a single connection for each query
print "\nPerformance:"
print("\nPerformance:")
for key, value in livestatus.SingleSiteConnection(socket_path).query_row_assoc(
"GET status").items():
print "%-30s: %s" % (key, value)
print "\nHosts:"
print("%-30s: %s" % (key, value))
print("\nHosts:")
hosts = livestatus.SingleSiteConnection(socket_path).query_table(
"GET hosts\nColumns: name alias address")
for name, alias, address in hosts:
print "%-16s %-16s %s" % (name, address, alias)
print("%-16s %-16s %s" % (name, address, alias))

# Do several queries in one connection
conn = livestatus.SingleSiteConnection(socket_path)
num_up = conn.query_value("GET hosts\nStats: hard_state = 0")
print "\nHosts up: %d" % num_up
print("\nHosts up: %d" % num_up)

stats = conn.query_row("GET services\n"
"Stats: state = 0\n"
"Stats: state = 1\n"
"Stats: state = 2\n"
"Stats: state = 3\n")
print "Service stats: %d/%d/%d/%d" % tuple(stats)
print("Service stats: %d/%d/%d/%d" % tuple(stats))

print "List of commands: %s" % \
", ".join(conn.query_column("GET commands\nColumns: name"))
print("List of commands: %s" % \
", ".join(conn.query_column("GET commands\nColumns: name")))

print "Query error:"
print("Query error:")
conn.query_value("GET hosts\nColumns: hirni")

except Exception as e: # livestatus.MKLivestatusException, e:
print "Livestatus error: %s" % str(e)
print("Livestatus error: %s" % str(e))
@@ -24,6 +24,7 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.

from __future__ import print_function
import os
import sys
import livestatus
@@ -58,12 +59,12 @@

c = livestatus.MultiSiteConnection(sites)
c.set_prepend_site(True)
print c.query("GET hosts\nColumns: name state\n")
print(c.query("GET hosts\nColumns: name state\n"))
c.set_prepend_site(False)
print c.query("GET hosts\nColumns: name state\n")
print(c.query("GET hosts\nColumns: name state\n"))

# Beware: When doing stats, you need to aggregate yourself:
print sum(c.query_column("GET hosts\nStats: state >= 0\n"))
print(sum(c.query_column("GET hosts\nStats: state >= 0\n")))

# Detect errors:
sites = {
@@ -87,7 +88,7 @@

c = livestatus.MultiSiteConnection(sites)
for name, state in c.query("GET hosts\nColumns: name state\n"):
print "%-15s: %d" % (name, state)
print "Dead sites:"
print("%-15s: %d" % (name, state))
print("Dead sites:")
for sitename, info in c.dead_sites().items():
print "%s: %s" % (sitename, info["exception"])
print("%s: %s" % (sitename, info["exception"]))
@@ -29,6 +29,7 @@
# system. Most things are hardcoded here but this might by
# a useful example for coding your own stuff...

from __future__ import print_function
import livestatus

g_y = 50
@@ -40,15 +41,15 @@


def make_label(text, x, y, width):
print """
print("""
define textbox {
text=%s
x=%d
y=%d
background_color=#C0C0C1
border_color=#000055
w=%d
}""" % (text, x, y, width)
}""" % (text, x, y, width))


def render_hostgroup(name, alias):
@@ -60,28 +61,28 @@ def render_hostgroup(name, alias):

def display_servicegroup(name, x):
if live.query_value("GET servicegroups\nStats: name = %s\n" % name) == 1:
print """
print("""
define servicegroup {
servicegroup_name = %s
x=%d
y=%d
}""" % (name, x, g_y)
}""" % (name, x, g_y))

# Einzelauflistung der Thermometer
num = 0
shift = 16
for host, service in live.query(
"GET services\nFilter: groups >= %s\nColumns: host_name description" % name):
num += 1
print """
print("""
define service {
host_name=%s
service_description=%s
x=%d
y=%d
url=/pnp4nagios/graph?host=%s&srv=%s
}
""" % (host, service, x + 30 + shift * num, g_y, host, service)
""" % (host, service, x + 30 + shift * num, g_y, host, service))

# Gesamtzustand Thermometer
display_servicegroup(name + "_therm", x_therm)
@@ -93,14 +94,14 @@ def display_servicegroup(name, x):
socket_path = "unix:/var/run/nagios/rw/live"
live = livestatus.SingleSiteConnection(socket_path)

print """
print("""
define global {
allowed_for_config=nagiosadmin
allowed_user=nagiosadmin
map_image=demo_background.png
iconset=std_medium
}
"""
""")

# hostgroups = live.query("GET hostgroups\nColumns: name alias")
hostgroups = [
@@ -24,6 +24,7 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.

from __future__ import print_function
import os, sys, stat

opt_debug = "-d" in sys.argv or "--debug" in sys.argv
@@ -620,21 +621,21 @@ def detect_omd():

detect_pnp()

print "# Result of autodetection"
print("# Result of autodetection")
for var, value in result.items():
print
print()
descr = target_values.get(var)
if descr:
print "# %s" % descr
print("# %s" % descr)
else:
print "# (unknown value)"
print "%s='%s'" % (var, value)
print("# (unknown value)")
print("%s='%s'" % (var, value))

for var, descr in target_values.items():
if var not in result:
print
print "# %s" % descr
print "# NOT DETECTED: %s" % var
print()
print("# %s" % descr)
print("# NOT DETECTED: %s" % var)

except Sorry as e:
sys.stderr.write("\033[1;41;35m Sorry: %s \033[0m\n" % e.reason)

0 comments on commit e9154bd

Please sign in to comment.
You can’t perform that action at this time.