from datetime import datetime
def status(agent, server_key, schedules, plugins):
"""
The 'status' argument allows the target machine's user to see various
metrics without having to go into the control panel.
"""
print("Agent Version %s Status\n------------\n" % agent.version)
# Print important config variables
print("Config Variables:\n------------")
print("Server Key: %s\nCommunication Endpoint: %s" % (server_key, agent.agg_url))
# Print out plugins
print("\nActive Plugins:\n------------")
for id, schedule in list(schedules.items()):
print("plugin name: %s" % schedule.plugin_textkey)
print("resource: %s" % schedule.resource_textkey)
print("params: %s" % str(schedule.option))
ch_minutes = int(schedule.frequency) / 60
print("check interval: %d minutes\n" % ch_minutes)
# Plugin status and errors
print("\nPlugin Errors: \n")
for key, value in plugins.metadata.items():
plugin_label = value[0]
metadict = value[1]
error_string = ""
for ikey in list(metadict.keys()):
if metadict[ikey].get("error_message") is not None:
error_string += "%s : %s\n" % (metadict[ikey]["label"], metadict[ikey]["error_message"])
if error_string != "":
print(plugin_label + "\n----")
print(error_string)
def stats(schedules, number_of_syncs, last_sync):
"""
The 'stats' argument displays to the user various statistics on the agent's
operations.
"""
print("Agent Statistics\n--------\n")
for id, schedule in list(schedules.items()):
print("plugin: %s" % schedule.plugin_textkey)
print("plugin params: %s" % str(schedule.option))
print("last check value: %s" % str(schedule.last_check_value))
print("next check time: %s\n" % datetime.ctime(schedule.next_check_time))
print("Number of agent syncs with server: %d" % number_of_syncs)
if last_sync:
last_sync_f = last_sync
else:
last_sync_f = "--"
print("Last succesful sync: %s" % last_sync_f)