Beispiel #1
0
def parse_zabbix_result(result,
                        key=None,
                        from_get_request=True,
                        many=False,
                        mon_object=None,
                        mon_object_name=None):
    if from_get_request:
        try:
            if not many and len(result) > 1:
                raise MultipleRemoteObjectsReturned(
                    'Got multiple (%d) zabbix objects when _one_ was expected'
                    % len(result))
            if key:
                return result[0][key]
            else:
                return result[0]
        except (KeyError, IndexError):
            raise RemoteObjectDoesNotExist(mon_object=mon_object,
                                           name=mon_object_name)
    else:
        try:
            if many:
                return result[key]
            else:
                return result[key][0]
        except (KeyError, IndexError):
            raise RemoteObjectManipulationError(mon_object=mon_object,
                                                name=mon_object_name)
Beispiel #2
0
    def _zabbix_get_children_serviceids(self, serviceid):
        """Query Zabbix API for children service IDs of the service ID given as argument;
        Used only once in node lifetime => no need for caching"""
        res = self.zapi.service.get({
            'parentids': serviceid,
        })

        try:
            return [i['serviceid'] for i in res]
        except (KeyError, IndexError) as e:
            logger.exception(e)
            raise RemoteObjectDoesNotExist(e)
Beispiel #3
0
    def _zabbix_get_sla(self, serviceid, start, end):
        """Query Zabbix API for SLA of service with id serviceid for time interval specified by start and end"""
        res = self.zapi.service.getsla({
            'serviceids': serviceid,
            'intervals': [
                {'from': start, 'to': end},
            ]
        })

        try:
            return res[serviceid]['sla'][0]['sla']
        except (KeyError, IndexError) as e:
            logger.exception(e)
            raise RemoteObjectDoesNotExist(e)
Beispiel #4
0
    def _get_proxy_id(self, proxy):
        """Return Zabbix proxy ID"""
        if not proxy:
            return self.NO_PROXY

        proxy = self._id_or_name(proxy)

        if isinstance(proxy, int):
            return proxy

        try:
            return int(self._zabbix_get_proxyid(proxy))
        except MonitoringError as ex:
            logger.exception(ex)
            raise RemoteObjectDoesNotExist('Cannot find zabbix proxy id for proxy "%s"' % proxy)
Beispiel #5
0
    def to_zabbix_data(self, dc_settings=settings):
        media_type_desc = self.get_media_type_desc(self.media_type,
                                                   dc_settings=dc_settings)

        if not media_type_desc:
            raise RemoteObjectDoesNotExist(
                detail='{mon_object} is not available',
                mon_object=MON_OBJ_MEDIA_TYPE,
                name=self.media_type)

        return {
            'mediatypeid': self.fetch_media_type_id(self._zapi,
                                                    media_type_desc),
            'sendto': self.sendto,
            'period': self.period,
            'severity': self.generate_media_severity(self.severities),
            'active': self.trans_bool_inverted(self.enabled),
        }