def addHostStatus(eventName, host_id, session_id, **params): """New host needs to be added to the monitor""" global _statusInfo, _runStatus #Only add if thread is running if _runStatus: host = ccs_host(session_id, host_id) name = host["host_name"] #Only add if host is active and not already in the list if host._properties["host_active"] and name not in _statusInfo: interval = config_get("status", "interval", DEFAULT_CHECK_INTERVAL) _statusInfo[name] = ccs_host_status(ADMIN_SESSION_ID, \ host_id, interval)
def __init__(self, session_id, host_id, interval=-1): """Initialises a new class for a specified host. The specified session must be valid and have appropriate access to the database. """ self.lock = threading.RLock() session = getSession(session_id) if session is None: raise ccs_host_error("Invalid session id") self._session_id = session_id # See if the specified host id makes sense self.host = ccs_host(session_id, host_id) self._hostname = self.host["host_name"] self._ip = self.host["ip_address"] # Initialise the status information self.reachable = False self.operatingRevision = -1 self.operatingRevisionStatus = STATUS_UNKNOWN self.operatingRevisionText = "Unknown" self.operatingRevisionHint = "Status not yet fetched" self.currentLoad = (-1,-1,-1) self.uptime = 0 self.infoUpdatedAt = 0 self.lastCheckedAt = time.time() self.interval = interval self.attempt = 0 # Retrieve locally available information self.activeRevision = getActiveRevision(self._hostname) self.generatedRevision = getGeneratedRevision(self._hostname) # Will this object be updated? if interval != -1: ccs_host_status.queue(time.time(), self) log_info("Initialised host status monitor for %s" % self._hostname)
def setupQuaggaService(eventName, session_id, host_id, **kwargs): """Watches events to detect when quagga has been added to a host. When a successful addition is detected the quagga configuration for the host is initialised. """ from crcnetd.modules.ccs_host import ccs_host # Bail out if the quagga service isn't configured yet if quagga_service.service_id == -1: return # Bail out if this isn't the quagga service being added if "service_id" not in kwargs.keys(): return if kwargs["service_id"] != quagga_service.service_id: return session = getSessionE(session_id) # Quagga service is being added, get a host instance host = ccs_host(session_id, host_id) # Enable OSPF on interfaces that have an area defined for their # link class. ifaces = host.getInterfaces() for idx,iface in ifaces.items(): if not iface["interface_active"]: continue area_no = quagga_service.getLinkArea(session_id, iface["link_id"]) if area_no == -1: continue sql = "INSERT INTO quagga_ospf_interface (host_id, " \ "interface_id, area_no, md5_auth) VALUES (%s, " \ "%s, %s, DEFAULT)" session.execute(sql, (host_id, iface["interface_id"], area_no))