def mon_vm_delete(task_id, sender, vm_uuid=None, vm_hostname=None, vm_alias=None, dc_id=None, zabbix_sync=None, external_zabbix_sync=None, log=LOG, **kwargs): """ Remove host from zabbix. """ assert vm_uuid assert dc_id assert zabbix_sync is not None assert external_zabbix_sync is not None # Create dummy VM object - used just to get zabbix_id and log things vm = Vm(uuid=vm_uuid, hostname=vm_hostname, alias=vm_alias) log.obj = vm.log_list if zabbix_sync or external_zabbix_sync: dc = Dc.objects.get_by_id(dc_id) return getZabbix(dc).vm_delete(Vm(uuid=vm_uuid, hostname=vm_hostname), internal=zabbix_sync, external=external_zabbix_sync, task_log=log) else: logger.info('Zabbix synchronization completely disabled for VM %s', vm_uuid) return None
def mon_node_status_sync(task_id, sender, node_uuid=None, log=LOG, **kwargs): """ Switch host status in zabbix according to node status. """ assert node_uuid node = log.obj = Node.objects.get(uuid=node_uuid) return getZabbix(DefaultDc()).node_status_sync(node, task_log=log)
def mon_node_sync(task_id, sender, node_uuid=None, log=LOG, **kwargs): """ Create or synchronize zabbix node host according to compute node. """ assert node_uuid node = log.obj = Node.objects.get(uuid=node_uuid) return getZabbix(DefaultDc()).node_sync(node, task_log=log)
def set_mon_zabbix_server_login_error(self): if self._changed_data and 'MON_ZABBIX_SERVER' in self._changed_data: return # Do not set error if setting has changed zx = getZabbix(self._request.dc) zx_error = zx.ezx.login_error if zx_error: self.set_error('MON_ZABBIX_SERVER', zx_error)
def mon_vm_disable(task_id, sender, vm_uuid=None, log=LOG, **kwargs): """ Switch host status in zabbix to not monitored. """ assert vm_uuid vm = log.obj = Vm.objects.select_related('dc').get(uuid=vm_uuid) if vm.is_zabbix_sync_active() or vm.is_external_zabbix_sync_active(): return getZabbix(vm.dc).vm_disable(vm, task_log=log) else: logger.info('Zabbix synchronization completely disabled for VM %s', vm) return None
def mon_node_delete(task_id, sender, node_uuid=None, node_hostname=None, log=LOG, **kwargs): """ Remove host from zabbix. """ assert node_uuid # Create dummy node object - used just to get zabbix_id and log things node = Node(uuid=node_uuid, hostname=node_hostname) log.obj = node.log_list return getZabbix(DefaultDc()).node_delete(node, task_log=log)
def mon_node_sla(task_id, node_hostname, yyyymm, since, until, **kwargs): """ Return SLA (%) for compute node / month. """ try: sla = getZabbix(DefaultDc()).node_sla(node_hostname, since, until) except ZabbixError as exc: raise MgmtTaskException(text_type(exc)) return { 'hostname': node_hostname, 'since': since, 'until': until, 'sla': round(sla, 4), }
def mon_clear_zabbix_cache(task_id, dc_id, full=True): """ Clear Zabbix instance from global zabbix cache used by getZabbix() if full==True. Reset internal zabbix instance cache if full==False and the zabbix instance exists in global zabbix cache. """ dc = Dc.objects.get_by_id(int(dc_id)) if full: if delZabbix(dc): logger.info('Zabbix instance for DC "%s" was successfully removed from global cache', dc) else: logger.info('Zabbix instance for DC "%s" was not found in global cache', dc) else: zx = getZabbix(dc) zx.reset_cache() logger.info('Cleared cache for zabbix instance %s in DC "%s"', zx, dc)
def mon_vm_sla(task_id, vm_hostname, yyyymm, vm_node_history, **kwargs): """ Return SLA (%) for VM / month. """ dc = Dc.objects.get_by_id(int(dc_id_from_task_id(task_id))) try: sla = getZabbix(dc).vm_sla(vm_node_history) except ZabbixError as exc: raise MgmtTaskException(text_type(exc)) result = { 'hostname': vm_hostname, 'since': vm_node_history[0]['since'], 'until': vm_node_history[-1]['till'], 'sla': round(sla, 4), } return result
def mon_node_history(task_id, node_uuid, items, zhistory, result, items_search, **kwargs): """ Return node's historical data for selected graph and period. """ try: history = getZabbix(DefaultDc()).node_history( node_uuid, items, zhistory, result['since'], result['until'], items_search=items_search) except ZabbixError as exc: raise MgmtTaskException(text_type(exc)) result.update(history) return result
def mon_vm_history(task_id, vm_uuid, items, zhistory, result, items_search, **kwargs): """ Return server history data for selected graph and period. """ dc = Dc.objects.get_by_id(int(dc_id_from_task_id(task_id))) try: history = getZabbix(dc).vm_history(vm_uuid, items, zhistory, result['since'], result['until'], items_search=items_search) except ZabbixError as exc: raise MgmtTaskException(text_type(exc)) result.update(history) return result
def mon_vm_sync(task_id, sender, vm_uuid=None, log=LOG, **kwargs): """ Create or synchronize zabbix host according to VM. """ assert vm_uuid vm = log.obj = Vm.objects.select_related('dc', 'slavevm').get(uuid=vm_uuid) log.dc_id = vm.dc.id # The "vm_zoneid_changed" case comes from api.vm.status.tasks callbacks if vm.is_slave_vm(): logger.info('Ignoring VM %s zabbix sync, because it is a slave VM', vm) return None if vm.is_deploying(): logger.warn( 'Ignoring VM %s zabbix sync, because it is currently being deployed', vm) return None # This can be also called via vm_zoneid_changed signal, where VM's DC is not available and # monitoring can be disabled in that DC if not vm.dc.settings.MON_ZABBIX_ENABLED: logger.info( 'Skipping VM %s zabbix sync, because zabbix module is completely disabled in DC %s', vm, vm.dc) return None zx = getZabbix(vm.dc) # Skip VM sync if called from vm_zoneid_changed signal and VM host does not exist in zabbix if 'zoneid' in kwargs: if not zx.is_vm_host_created(vm): logger.warn( 'Ignoring VM %s zabbix sync, because it does not exist in zabbix yet', vm) return None force_update = True else: force_update = kwargs.get('force_update', False) return zx.vm_sync(vm, force_update=force_update, task_log=log)