def getStatus(session_id, host_id): """Returns a dictionary describing the status of the host""" # Get some basic info hostname = getHostName(session_id, host_id) hoststatus = getHostStatus(hostname) # Get the host's CFengine status status = getCfengineHostStatus(session_id, hoststatus.host._properties) # Get state information status["reachable"] = hoststatus.reachable status["operating_rev"] = hoststatus.operatingRevision status["operating_rev_status"] = hoststatus.operatingRevisionStatus status["operating_rev_text"] = hoststatus.operatingRevisionText status["operating_rev_hint"] = hoststatus.operatingRevisionHint status["active_rev"] = hoststatus.activeRevision status["generated_rev"] = hoststatus.generatedRevision status["current_load"] = hoststatus.currentLoad status["uptime"] = hoststatus.uptime status["infoUpdatedAt"] = time.strftime("%d/%m/%Y %H:%M:%S", \ time.localtime(hoststatus.infoUpdatedAt)) status["lastCheckedAt"] = time.strftime("%d/%m/%Y %H:%M:%S", \ time.localtime(hoststatus.lastCheckedAt)) return status
def delHostStatus(eventName, host_id, session_id, **params): """Host has been deleted so remove from the monitor""" global _statusInfo host_name = getHostName(session_id, host_id) #Only remove if it is in the list if host_name in _statusInfo.keys(): del _statusInfo[host_name] log_debug("Removed host status monitor for %s" % (host_name))
def changeHostName(eventName, host_id, session_id, **params): """Hosts name changed so change the name in the monitor""" global _statusInfo old_name = params["old_name"] host_name = getHostName(session_id, host_id) log_debug("Changing host status monitor for %s to %s" % (old_name, host_name)) if old_name not in _statusInfo.keys(): raise ccs_status_error("Cannot rename %s as does not exist" % old_name) _statusInfo[host_name] = _statusInfo[old_name] del _statusInfo[old_name]