mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
python: Convert percent formatting to Python 3.6 f-strings.
Generated by pyupgrade --py36-plus. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
6480deaf27
commit
67e7a3631d
@@ -36,7 +36,7 @@ def nagios_from_file(results_file: str, max_time_diff: int=60 * 2) -> 'Tuple[int
|
||||
state = pieces[2]
|
||||
data = pieces[3]
|
||||
|
||||
return (ret, "%s: %s" % (state, data))
|
||||
return (ret, f"{state}: {data}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
RESULTS_FILE = sys.argv[1]
|
||||
|
||||
@@ -12,7 +12,7 @@ import sys
|
||||
wildcard = os.path.join("/var/log/zulip/queue_error", '*.errors')
|
||||
clean = True
|
||||
for fn in glob.glob(wildcard):
|
||||
print('WARNING: Queue errors logged in %s' % (fn,))
|
||||
print(f'WARNING: Queue errors logged in {fn}')
|
||||
clean = False
|
||||
|
||||
if not clean:
|
||||
|
||||
@@ -17,7 +17,7 @@ if len(sys.argv) < 2:
|
||||
print("Please pass the name of the consumer file to check")
|
||||
exit(1)
|
||||
|
||||
RESULTS_FILE = "/var/lib/nagios_state/check-rabbitmq-consumers-%s" % (sys.argv[1],)
|
||||
RESULTS_FILE = f"/var/lib/nagios_state/check-rabbitmq-consumers-{sys.argv[1]}"
|
||||
|
||||
ret, result = nagios_from_file(RESULTS_FILE)
|
||||
|
||||
|
||||
@@ -88,24 +88,24 @@ states = {
|
||||
def report(state: str, timestamp: Any = None, msg: Optional[str] = None) -> None:
|
||||
now = int(time.time())
|
||||
if msg is None:
|
||||
msg = "send time was %s" % (timestamp,)
|
||||
msg = f"send time was {timestamp}"
|
||||
state_file_path = "/var/lib/nagios_state/check_send_receive_state"
|
||||
with open(state_file_path + ".tmp", 'w') as f:
|
||||
f.write("%s|%s|%s|%s\n" % (now, states[state], state, msg))
|
||||
f.write(f"{now}|{states[state]}|{state}|{msg}\n")
|
||||
os.rename(state_file_path + ".tmp", state_file_path)
|
||||
print("%s: %s" % (state, msg))
|
||||
print(f"{state}: {msg}")
|
||||
exit(states[state])
|
||||
|
||||
def send_zulip(sender: zulip.Client, message: Dict[str, Any]) -> None:
|
||||
result = sender.send_message(message)
|
||||
if result["result"] != "success" and options.nagios:
|
||||
report("CRITICAL", msg="Error sending Zulip, args were: %s, %s" % (message, result))
|
||||
report("CRITICAL", msg=f"Error sending Zulip, args were: {message}, {result}")
|
||||
|
||||
def get_zulips() -> List[Dict[str, Any]]:
|
||||
global queue_id, last_event_id
|
||||
res = zulip_recipient.get_events(queue_id=queue_id, last_event_id=last_event_id)
|
||||
if 'error' in res.get('result', {}):
|
||||
report("CRITICAL", msg="Error receiving Zulips, error was: %s" % (res["msg"],))
|
||||
report("CRITICAL", msg="Error receiving Zulips, error was: {}".format(res["msg"]))
|
||||
for event in res['events']:
|
||||
last_event_id = max(last_event_id, int(event['id']))
|
||||
# If we get a heartbeat event, that means we've been hanging for
|
||||
@@ -141,10 +141,10 @@ zulip_recipient = zulip.Client(
|
||||
try:
|
||||
res = zulip_recipient.register(event_types=["message"])
|
||||
if 'error' in res.get('result', {}):
|
||||
report("CRITICAL", msg="Error subscribing to Zulips: %s" % (res['msg'],))
|
||||
report("CRITICAL", msg="Error subscribing to Zulips: {}".format(res['msg']))
|
||||
queue_id, last_event_id = (res['queue_id'], res['last_event_id'])
|
||||
except Exception:
|
||||
report("CRITICAL", msg="Error subscribing to Zulips:\n%s" % (traceback.format_exc(),))
|
||||
report("CRITICAL", msg=f"Error subscribing to Zulips:\n{traceback.format_exc()}")
|
||||
msg_to_send = str(random.getrandbits(64))
|
||||
time_start = time.time()
|
||||
|
||||
@@ -172,6 +172,6 @@ if options.nagios:
|
||||
report('WARNING', timestamp=seconds_diff)
|
||||
|
||||
if options.munin:
|
||||
print("sendreceive.value %s" % (seconds_diff,))
|
||||
print(f"sendreceive.value {seconds_diff}")
|
||||
elif options.nagios:
|
||||
report('OK', timestamp=seconds_diff)
|
||||
|
||||
@@ -22,17 +22,17 @@ states = {
|
||||
}
|
||||
|
||||
def report(state: str, msg: str) -> "NoReturn":
|
||||
print("%s: %s" % (state, msg))
|
||||
print(f"{state}: {msg}")
|
||||
exit(states[state])
|
||||
|
||||
def get_loc_over_ssh(host: str, func: str) -> str:
|
||||
try:
|
||||
return subprocess.check_output(['ssh', host,
|
||||
'psql -v ON_ERROR_STOP=1 zulip -t -c "SELECT %s()"' % (func,)],
|
||||
f'psql -v ON_ERROR_STOP=1 zulip -t -c "SELECT {func}()"'],
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
report('CRITICAL', 'ssh failed: %s: %s' % (str(e), e.output))
|
||||
report('CRITICAL', f'ssh failed: {str(e)}: {e.output}')
|
||||
|
||||
def loc_to_abs_offset(loc_str: str) -> int:
|
||||
m = re.match(r'^\s*([0-9a-fA-F]+)/([0-9a-fA-F]+)\s*$', loc_str)
|
||||
|
||||
@@ -22,7 +22,7 @@ states = {
|
||||
}
|
||||
|
||||
def report(state: str, num: str) -> None:
|
||||
print("%s: %s rows in fts_update_log table" % (state, num))
|
||||
print(f"{state}: {num} rows in fts_update_log table")
|
||||
exit(states[state])
|
||||
|
||||
conn = psycopg2.connect(database="zulip")
|
||||
|
||||
@@ -13,7 +13,7 @@ states = {
|
||||
}
|
||||
|
||||
def report(state: str, msg: str) -> None:
|
||||
print("%s: %s" % (state, msg))
|
||||
print(f"{state}: {msg}")
|
||||
exit(states[state])
|
||||
|
||||
if subprocess.check_output(['psql', '-v', 'ON_ERROR_STOP=1',
|
||||
@@ -28,6 +28,6 @@ except OSError:
|
||||
report('UNKNOWN', 'could not determine completion time of last Postgres backup')
|
||||
|
||||
if datetime.now(tz=timezone.utc) - last_backup > timedelta(hours=25):
|
||||
report('CRITICAL', 'last Postgres backup completed more than 25 hours ago: %s' % (last_backup,))
|
||||
report('CRITICAL', f'last Postgres backup completed more than 25 hours ago: {last_backup}')
|
||||
|
||||
report('OK', 'last Postgres backup completed less than 25 hours ago: %s' % (last_backup,))
|
||||
report('OK', f'last Postgres backup completed less than 25 hours ago: {last_backup}')
|
||||
|
||||
@@ -42,7 +42,7 @@ if is_rhel_based:
|
||||
else:
|
||||
pg_data_paths = glob.glob('/var/lib/postgresql/*/main')
|
||||
if len(pg_data_paths) != 1:
|
||||
print("Postgres installation is not unique: %s" % (pg_data_paths,))
|
||||
print(f"Postgres installation is not unique: {pg_data_paths}")
|
||||
sys.exit(1)
|
||||
pg_data_path = pg_data_paths[0]
|
||||
run(['env-wal-e', 'backup-push', pg_data_path])
|
||||
|
||||
@@ -142,7 +142,7 @@ while True:
|
||||
# Catch up on any historical columns
|
||||
while True:
|
||||
rows_updated = update_fts_columns(cursor)
|
||||
notice = "Processed %s rows catching up" % (rows_updated,)
|
||||
notice = f"Processed {rows_updated} rows catching up"
|
||||
if rows_updated > 0:
|
||||
logger.info(notice)
|
||||
else:
|
||||
|
||||
@@ -22,7 +22,7 @@ states: Dict[str, int] = {
|
||||
}
|
||||
|
||||
def report(state: str, output: str) -> None:
|
||||
print("%s\n%s" % (state, output))
|
||||
print(f"{state}\n{output}")
|
||||
exit(states[state])
|
||||
|
||||
output = ""
|
||||
@@ -41,7 +41,7 @@ for results_file_name in os.listdir(RESULTS_DIR):
|
||||
down_count += 1
|
||||
this_state = "DOWN"
|
||||
last_check_ts = time.strftime("%Y-%m-%d %H:%M %Z", time.gmtime(last_check))
|
||||
output += "%s: %s (%s)\n" % (results_file, this_state, last_check_ts)
|
||||
output += f"{results_file}: {this_state} ({last_check_ts})\n"
|
||||
|
||||
if down_count == 0:
|
||||
state = "OK"
|
||||
|
||||
@@ -39,11 +39,11 @@ def report(state: str, short_msg: str, too_old: Optional[Set[Any]] = None) -> No
|
||||
too_old_data = ""
|
||||
if too_old:
|
||||
too_old_data = "\nLast call to get_message for recently out of date mirrors:\n" + "\n".join(
|
||||
["%16s: %s" % (user.user_profile.email,
|
||||
user.last_visit.strftime("%Y-%m-%d %H:%M %Z")
|
||||
) for user in too_old]
|
||||
["{:>16}: {}".format(user.user_profile.email,
|
||||
user.last_visit.strftime("%Y-%m-%d %H:%M %Z")
|
||||
) for user in too_old]
|
||||
)
|
||||
print("%s: %s%s" % (state, short_msg, too_old_data))
|
||||
print(f"{state}: {short_msg}{too_old_data}")
|
||||
|
||||
exit(states[state])
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ states: Dict[str, int] = {
|
||||
}
|
||||
|
||||
def report(state: str, data: str, last_check: float) -> None:
|
||||
print("%s: Last test run completed at %s\n%s" % (
|
||||
print("{}: Last test run completed at {}\n{}".format(
|
||||
state, time.strftime("%Y-%m-%d %H:%M %Z", time.gmtime(last_check)),
|
||||
data))
|
||||
exit(states[state])
|
||||
|
||||
@@ -131,7 +131,7 @@ for device in macs.values():
|
||||
for (count, ip) in enumerate(to_configure):
|
||||
# Configure the IP via a virtual interface
|
||||
device = "ens%i:%i" % (device_number, count)
|
||||
log.info("Configuring %s with IP %s" % (device, ip))
|
||||
log.info(f"Configuring {device} with IP {ip}")
|
||||
subprocess.check_call(['/sbin/ifconfig', device, ip])
|
||||
subprocess.check_call(
|
||||
['/sbin/iptables', '-t', 'mangle', '-A', 'OUTPUT', '-m', 'conntrack', '--ctorigdst',
|
||||
|
||||
Reference in New Issue
Block a user