Zabbix datasource
Change-Id: I0b2865169b5c47a71a12d6e91e719bfb2c616bc3
This commit is contained in:
parent
e7956c2c57
commit
a63fff4f1f
31
etc/vitrage/datasources_values/zabbix.yaml
Normal file
31
etc/vitrage/datasources_values/zabbix.yaml
Normal file
@ -0,0 +1,31 @@
|
||||
category: ALARM
|
||||
values:
|
||||
- aggregated values:
|
||||
priority: 50
|
||||
original values:
|
||||
- name: HIGH
|
||||
operational_value: CRITICAL
|
||||
- name: DISASTER
|
||||
operational_value: CRITICAL
|
||||
- aggregated values:
|
||||
priority: 40
|
||||
original values:
|
||||
- name: AVERAGE
|
||||
operational_value: SEVERE
|
||||
- aggregated values:
|
||||
priority: 30
|
||||
original values:
|
||||
- name: WARNING
|
||||
operational_value: WARNING
|
||||
- aggregated values:
|
||||
priority: 20
|
||||
original values:
|
||||
- name: NOT CLASSIFIED
|
||||
operational_value: N/A
|
||||
- aggregated values:
|
||||
priority: 10
|
||||
original values:
|
||||
- name: OK
|
||||
operational_value: OK
|
||||
- name: INFORMATION
|
||||
operational_value: OK
|
@ -11,6 +11,7 @@ python-dateutil>=2.4.2
|
||||
python-keystoneclient!=1.8.0,!=2.1.0,>=1.6.0 # Apache-2.0
|
||||
python-neutronclient!=4.1.0,>=2.6.0 # Apache-2.0
|
||||
python-novaclient>=2.26.0
|
||||
pyzabbix>=0.7.4 # LGPL
|
||||
networkx>=1.10
|
||||
oslo.config>=2.7.0 # Apache-2.0
|
||||
oslo.messaging>=4.5.0 # Apache-2.0
|
||||
|
@ -13,6 +13,7 @@ python-cinderclient>=1.3.1 # Apache-2.0
|
||||
python-neutronclient!=4.1.0,>=2.6.0 # Apache-2.0
|
||||
python-novaclient>=2.26.0
|
||||
python-subunit>=0.0.18
|
||||
pyzabbix>=0.7.4 # LGPL
|
||||
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2
|
||||
oslo.log>=1.12.0 # Apache-2.0
|
||||
oslosphinx>=2.5.0 # Apache-2.0
|
||||
|
@ -84,9 +84,8 @@ class AlarmDriverBase(DriverBase):
|
||||
def _get_all_alarms(self):
|
||||
alarms = self._get_alarms()
|
||||
self._enrich_alarms(alarms)
|
||||
return self._filter_and_cache_alarms(
|
||||
alarms,
|
||||
AlarmDriverBase._filter_get_all)
|
||||
return self._filter_and_cache_alarms(alarms,
|
||||
AlarmDriverBase._filter_get_all)
|
||||
|
||||
def _get_changed_alarms(self):
|
||||
alarms = self._get_alarms()
|
||||
|
@ -15,5 +15,5 @@ __author__ = 'stack'
|
||||
|
||||
|
||||
class AlarmProperties(object):
|
||||
ALARM_ACTIVE_STATE = 'Active'
|
||||
ALARM_INACTIVE_STATE = 'Inactive'
|
||||
ACTIVE_STATE = 'Active'
|
||||
INACTIVE_STATE = 'Inactive'
|
||||
|
@ -60,10 +60,10 @@ class AlarmTransformerBase(tbase.TransformerBase):
|
||||
def _get_alarm_state(self, entity_event):
|
||||
event_type = entity_event.get(DSProps.EVENT_TYPE, None)
|
||||
if event_type is not None:
|
||||
return AlarmProps.ALARM_INACTIVE_STATE if \
|
||||
return AlarmProps.INACTIVE_STATE if \
|
||||
EventAction.DELETE_ENTITY == event_type else \
|
||||
AlarmProps.ALARM_ACTIVE_STATE
|
||||
AlarmProps.ACTIVE_STATE
|
||||
else:
|
||||
return AlarmProps.ALARM_INACTIVE_STATE if \
|
||||
return AlarmProps.INACTIVE_STATE if \
|
||||
self._ok_status(entity_event) else \
|
||||
AlarmProps.ALARM_ACTIVE_STATE
|
||||
AlarmProps.ACTIVE_STATE
|
||||
|
@ -11,6 +11,7 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_log import log as logging
|
||||
|
||||
from vitrage.common.constants import DatasourceProperties as DSProps
|
||||
|
@ -35,7 +35,8 @@ OPTS = [
|
||||
help='Nagios user name'),
|
||||
cfg.StrOpt('password', default='nagiosadmin',
|
||||
help='Nagios user password'),
|
||||
cfg.StrOpt('url', default='', help='Nagios url'),
|
||||
cfg.StrOpt('url', default='',
|
||||
help='Nagios url'),
|
||||
cfg.StrOpt('config_file', default='/etc/vitrage/nagios_conf.yaml',
|
||||
help='Nagios configuration file'),
|
||||
]
|
||||
|
@ -34,7 +34,6 @@ class NagiosConfig(object):
|
||||
nagios = nagios_config[NAGIOS] # nagios root in the yaml file
|
||||
|
||||
self.mappings = [self._create_mapping(config) for config in nagios]
|
||||
|
||||
except Exception as e:
|
||||
LOG.exception('failed in init %s ', e)
|
||||
self.mappings = []
|
||||
|
@ -24,7 +24,7 @@ from vitrage.datasources.nagios import NAGIOS_DATASOURCE
|
||||
from vitrage.datasources.nagios.parser import NagiosParser
|
||||
from vitrage.datasources.nagios.properties import NagiosProperties\
|
||||
as NagiosProps
|
||||
from vitrage.datasources.nagios.properties import NagiosStatus
|
||||
from vitrage.datasources.nagios.properties import NagiosTestStatus
|
||||
# noinspection PyProtectedMember
|
||||
from vitrage.i18n import _LE
|
||||
# noinspection PyProtectedMember
|
||||
@ -94,7 +94,7 @@ class NagiosDriver(AlarmDriverBase):
|
||||
vitrage_resource[1] if vitrage_resource else None
|
||||
|
||||
def _is_erroneous(self, alarm):
|
||||
return alarm and alarm[NagiosProps.STATUS] != NagiosStatus.OK
|
||||
return alarm and alarm[NagiosProps.STATUS] != NagiosTestStatus.OK
|
||||
|
||||
def _status_changed(self, alarm1, alarm2):
|
||||
return alarm1 and alarm2 and \
|
||||
|
@ -26,7 +26,7 @@ class NagiosProperties(object):
|
||||
NAGIOS = 'nagios'
|
||||
|
||||
|
||||
class NagiosStatus(object):
|
||||
class NagiosTestStatus(object):
|
||||
OK = 'OK'
|
||||
WARNING = 'WARNING'
|
||||
CRITICAL = 'CRITICAL'
|
||||
|
@ -21,6 +21,7 @@ from vitrage.common.constants import VertexProperties as VProps
|
||||
from vitrage.common import datetime_utils
|
||||
from vitrage.datasources.alarm_transformer_base import AlarmTransformerBase
|
||||
from vitrage.datasources.nagios.properties import NagiosProperties
|
||||
from vitrage.datasources.nagios.properties import NagiosTestStatus
|
||||
from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE
|
||||
from vitrage.datasources.static_physical import SWITCH
|
||||
from vitrage.datasources import transformer_base as tbase
|
||||
@ -32,8 +33,6 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
class NagiosTransformer(AlarmTransformerBase):
|
||||
|
||||
STATUS_OK = 'OK'
|
||||
|
||||
def __init__(self, transformers):
|
||||
super(NagiosTransformer, self).__init__(transformers)
|
||||
|
||||
@ -120,7 +119,7 @@ class NagiosTransformer(AlarmTransformerBase):
|
||||
return None
|
||||
|
||||
def _ok_status(self, entity_event):
|
||||
return entity_event[NagiosProperties.STATUS] == self.STATUS_OK
|
||||
return entity_event[NagiosProperties.STATUS] == NagiosTestStatus.OK
|
||||
|
||||
def _create_entity_key(self, entity_event):
|
||||
|
||||
|
@ -62,8 +62,9 @@ class SnapshotsService(DatasourceService):
|
||||
entities_dictionaries = plugin.get_all(sync_mode)
|
||||
for entity in entities_dictionaries:
|
||||
self.callback_function(entity)
|
||||
except Exception as e:
|
||||
LOG.error("Get all Failed - %s - %s", plugin_type, e.message)
|
||||
except Exception:
|
||||
LOG.error("'Get all' Failed for datasource: %s", plugin_type)
|
||||
LOG.exception(plugin_type)
|
||||
|
||||
LOG.debug("end get all with sync mode %s" % sync_mode)
|
||||
self.first_time = False
|
||||
|
42
vitrage/datasources/zabbix/__init__.py
Normal file
42
vitrage/datasources/zabbix/__init__.py
Normal file
@ -0,0 +1,42 @@
|
||||
# Copyright 2016 - Nokia
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
ZABBIX_DATASOURCE = 'zabbix'
|
||||
|
||||
OPTS = [
|
||||
cfg.StrOpt('transformer',
|
||||
default='vitrage.datasources.zabbix.transformer.'
|
||||
'ZabbixTransformer',
|
||||
help='Zabbix transformer class path',
|
||||
required=True),
|
||||
cfg.StrOpt('driver',
|
||||
default='vitrage.datasources.zabbix.driver.ZabbixDriver',
|
||||
help='Zabbix driver class path',
|
||||
required=True),
|
||||
cfg.IntOpt('changes_interval',
|
||||
default=30,
|
||||
min=30,
|
||||
help='interval between checking changes in zabbix data source',
|
||||
required=True),
|
||||
cfg.StrOpt('user', default='admin',
|
||||
help='Zabbix user name'),
|
||||
cfg.StrOpt('password', default='zabbix',
|
||||
help='Zabbix user password'),
|
||||
cfg.StrOpt('url', default='',
|
||||
help='Zabbix url'),
|
||||
cfg.StrOpt('config_file', default='/etc/vitrage/zabbix_conf.yaml',
|
||||
help='Zabbix configuration file'),
|
||||
]
|
144
vitrage/datasources/zabbix/driver.py
Normal file
144
vitrage/datasources/zabbix/driver.py
Normal file
@ -0,0 +1,144 @@
|
||||
# Copyright 2016 - Nokia
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
from oslo_log import log
|
||||
from pyzabbix import ZabbixAPI
|
||||
|
||||
from vitrage.common import file_utils
|
||||
from vitrage.datasources.alarm_driver_base import AlarmDriverBase
|
||||
from vitrage.datasources.zabbix.properties import ZabbixProperties \
|
||||
as ZabbixProps
|
||||
from vitrage.datasources.zabbix.properties import ZabbixTriggerStatus
|
||||
from vitrage.datasources.zabbix import ZABBIX_DATASOURCE
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class ZabbixDriver(AlarmDriverBase):
|
||||
ServiceKey = namedtuple('ServiceKey', ['host_name', 'service'])
|
||||
|
||||
def __init__(self, conf):
|
||||
super(ZabbixDriver, self).__init__()
|
||||
self.conf = conf
|
||||
self.configuration_mapping = self._configuration_mapping(conf)
|
||||
self.status_mapping = self._status_mapping()
|
||||
self.client = None
|
||||
|
||||
def _sync_type(self):
|
||||
return ZABBIX_DATASOURCE
|
||||
|
||||
def _alarm_key(self, alarm):
|
||||
return self.ServiceKey(host_name=alarm[ZabbixProps.RESOURCE_NAME],
|
||||
service=alarm[ZabbixProps.DESCRIPTION])
|
||||
|
||||
def _get_alarms(self):
|
||||
zabbix_user = self.conf.zabbix.user
|
||||
zabbix_password = self.conf.zabbix.password
|
||||
zabbix_url = self.conf.zabbix.url
|
||||
|
||||
if not zabbix_user:
|
||||
LOG.warning('Zabbix user is not defined')
|
||||
return []
|
||||
|
||||
if not zabbix_password:
|
||||
LOG.warning('Zabbix password is not defined')
|
||||
return []
|
||||
|
||||
if not zabbix_url:
|
||||
LOG.warning('Zabbix url is not defined')
|
||||
return []
|
||||
|
||||
if not self.client:
|
||||
self.client = ZabbixAPI(zabbix_url)
|
||||
self.client.login(zabbix_user, zabbix_password)
|
||||
|
||||
alarms = []
|
||||
hosts = self.client.host.get()
|
||||
for host in hosts:
|
||||
if host[ZabbixProps.HOST] in self.configuration_mapping:
|
||||
self._get_triggers_per_host(host, alarms)
|
||||
|
||||
return alarms
|
||||
|
||||
def _enrich_alarms(self, alarms):
|
||||
for alarm in alarms:
|
||||
# based on zabbix configuration file, convert zabbix host name
|
||||
# to vitrage resource type and name
|
||||
zabbix_host = alarm[ZabbixProps.RESOURCE_NAME]
|
||||
vitrage_resource = self.configuration_mapping[zabbix_host]
|
||||
|
||||
alarm[ZabbixProps.STATUS] = \
|
||||
self._get_status(alarm)
|
||||
alarm[ZabbixProps.RESOURCE_TYPE] = \
|
||||
vitrage_resource[ZabbixProps.RESOURCE_TYPE]
|
||||
alarm[ZabbixProps.RESOURCE_NAME] = \
|
||||
vitrage_resource[ZabbixProps.RESOURCE_NAME]
|
||||
|
||||
def _is_erroneous(self, alarm):
|
||||
return alarm and alarm[ZabbixProps.STATUS] != ZabbixTriggerStatus.OK
|
||||
|
||||
def _status_changed(self, alarm1, alarm2):
|
||||
return alarm1 and alarm2 and \
|
||||
not alarm1[ZabbixProps.STATUS] == alarm2[ZabbixProps.STATUS]
|
||||
|
||||
def _is_valid(self, alarm):
|
||||
return alarm[ZabbixProps.RESOURCE_TYPE] is not None and \
|
||||
alarm[ZabbixProps.RESOURCE_NAME] is not None
|
||||
|
||||
def _get_status(self, alarm):
|
||||
if alarm[ZabbixProps.IS_ALARM_DISABLED] == '1' or \
|
||||
alarm[ZabbixProps.IS_ALARM_ON] == '0':
|
||||
return ZabbixTriggerStatus.OK
|
||||
|
||||
return self.status_mapping[alarm[ZabbixProps.SEVERITY]]
|
||||
|
||||
@staticmethod
|
||||
def _status_mapping():
|
||||
return {
|
||||
'-1': ZabbixTriggerStatus.OK,
|
||||
'0': ZabbixTriggerStatus.NOT_CLASSIFIED,
|
||||
'1': ZabbixTriggerStatus.INFORMATION,
|
||||
'2': ZabbixTriggerStatus.WARNING,
|
||||
'3': ZabbixTriggerStatus.AVERAGE,
|
||||
'4': ZabbixTriggerStatus.HIGH,
|
||||
'5': ZabbixTriggerStatus.DISASTER
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _configuration_mapping(conf):
|
||||
try:
|
||||
zabbix_config_file = conf.zabbix['config_file']
|
||||
zabbix_config = file_utils.load_yaml_file(zabbix_config_file)
|
||||
zabbix_config_elements = zabbix_config['zabbix']
|
||||
|
||||
mappings = {}
|
||||
for element_config in zabbix_config_elements:
|
||||
mappings[element_config['zabbix_host']] = {
|
||||
ZabbixProps.RESOURCE_TYPE: element_config['type'],
|
||||
ZabbixProps.RESOURCE_NAME: element_config['name']
|
||||
}
|
||||
|
||||
return mappings
|
||||
except Exception as e:
|
||||
LOG.exception('failed in init %s ', e)
|
||||
return {}
|
||||
|
||||
def _get_triggers_per_host(self, host, alarms):
|
||||
host_ids = host[ZabbixProps.HOST_ID]
|
||||
triggers = self.client.trigger.get(hostids=host_ids)
|
||||
for trigger in triggers:
|
||||
trigger[ZabbixProps.RESOURCE_NAME] = host[ZabbixProps.HOST]
|
||||
alarms.append(trigger)
|
36
vitrage/datasources/zabbix/properties.py
Normal file
36
vitrage/datasources/zabbix/properties.py
Normal file
@ -0,0 +1,36 @@
|
||||
# Copyright 2016 - Nokia
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
class ZabbixProperties(object):
|
||||
RESOURCE_TYPE = 'resource_type'
|
||||
RESOURCE_NAME = 'resource_name'
|
||||
DESCRIPTION = 'description'
|
||||
STATUS = 'status'
|
||||
HOST = 'host'
|
||||
HOST_ID = 'hostid'
|
||||
IS_ALARM_DISABLED = 'status'
|
||||
IS_ALARM_ON = 'value'
|
||||
SEVERITY = 'priority'
|
||||
LAST_CHANGE = 'lastchange'
|
||||
|
||||
|
||||
class ZabbixTriggerStatus(object):
|
||||
OK = 'OK'
|
||||
INFORMATION = 'INFORMATION'
|
||||
WARNING = 'WARNING'
|
||||
AVERAGE = 'AVERAGE'
|
||||
HIGH = 'HIGH'
|
||||
DISASTER = 'DISASTER'
|
||||
NOT_CLASSIFIED = 'NOT CLASSIFIED'
|
137
vitrage/datasources/zabbix/transformer.py
Normal file
137
vitrage/datasources/zabbix/transformer.py
Normal file
@ -0,0 +1,137 @@
|
||||
# Copyright 2016 - Nokia
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_log import log as logging
|
||||
|
||||
from vitrage.common.constants import DatasourceProperties as DSProps
|
||||
from vitrage.common.constants import EdgeLabel
|
||||
from vitrage.common.constants import EntityCategory
|
||||
from vitrage.common.constants import VertexProperties as VProps
|
||||
from vitrage.datasources.alarm_properties import AlarmProperties as AlarmProps
|
||||
from vitrage.datasources.alarm_transformer_base import AlarmTransformerBase
|
||||
from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE
|
||||
from vitrage.datasources.static_physical import SWITCH
|
||||
from vitrage.datasources import transformer_base as tbase
|
||||
from vitrage.datasources.transformer_base import Neighbor
|
||||
from vitrage.datasources.zabbix.properties import ZabbixProperties
|
||||
from vitrage.datasources.zabbix.properties import ZabbixTriggerStatus
|
||||
import vitrage.graph.utils as graph_utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ZabbixTransformer(AlarmTransformerBase):
|
||||
|
||||
def __init__(self, transformers):
|
||||
super(ZabbixTransformer, self).__init__(transformers)
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
return self._create_vertex(entity_event)
|
||||
|
||||
def _create_update_entity_vertex(self, entity_event):
|
||||
return self._create_vertex(entity_event)
|
||||
|
||||
def _create_vertex(self, entity_event):
|
||||
# TODO(Alexey): need to check the correct format for the date
|
||||
# update_timestamp = datetime_utils.change_time_str_format(
|
||||
# entity_event[ZabbixProperties.LAST_CHANGE],
|
||||
# '%Y-%m-%d %H:%M:%S',
|
||||
# tbase.TIMESTAMP_FORMAT)
|
||||
update_timestamp = entity_event[ZabbixProperties.LAST_CHANGE]
|
||||
|
||||
sample_timestamp = entity_event[DSProps.SAMPLE_DATE]
|
||||
|
||||
update_timestamp = self._format_update_timestamp(update_timestamp,
|
||||
sample_timestamp)
|
||||
|
||||
severity = entity_event[ZabbixProperties.STATUS]
|
||||
entity_state = AlarmProps.INACTIVE_STATE if \
|
||||
severity == ZabbixTriggerStatus.OK else AlarmProps.ACTIVE_STATE
|
||||
|
||||
metadata = {
|
||||
VProps.NAME: entity_event[ZabbixProperties.DESCRIPTION],
|
||||
VProps.SEVERITY: severity
|
||||
}
|
||||
|
||||
return graph_utils.create_vertex(
|
||||
self._create_entity_key(entity_event),
|
||||
entity_category=EntityCategory.ALARM,
|
||||
entity_type=entity_event[DSProps.SYNC_TYPE],
|
||||
entity_state=entity_state,
|
||||
sample_timestamp=sample_timestamp,
|
||||
update_timestamp=update_timestamp,
|
||||
metadata=metadata)
|
||||
|
||||
def _create_snapshot_neighbors(self, entity_event):
|
||||
return self._create_zabbix_neighbors(entity_event)
|
||||
|
||||
def _create_update_neighbors(self, entity_event):
|
||||
return self._create_zabbix_neighbors(entity_event)
|
||||
|
||||
def _create_zabbix_neighbors(self, entity_event):
|
||||
vitrage_id = self._create_entity_key(entity_event)
|
||||
# TODO(Alexey): need to check the correct format for the date
|
||||
# timestamp = datetime_utils.change_time_str_format(
|
||||
# entity_event[ZabbixProperties.LAST_CHANGE],
|
||||
# '%Y-%m-%d %H:%M:%S',
|
||||
# tbase.TIMESTAMP_FORMAT)
|
||||
timestamp = entity_event[DSProps.SAMPLE_DATE]
|
||||
|
||||
resource_type = entity_event[ZabbixProperties.RESOURCE_TYPE]
|
||||
if resource_type == NOVA_HOST_DATASOURCE or resource_type == SWITCH:
|
||||
return [self._create_neighbor(
|
||||
vitrage_id,
|
||||
timestamp,
|
||||
resource_type,
|
||||
entity_event[ZabbixProperties.RESOURCE_NAME])]
|
||||
|
||||
return []
|
||||
|
||||
def _create_neighbor(self,
|
||||
vitrage_id,
|
||||
sample_timestamp,
|
||||
resource_type,
|
||||
resource_name):
|
||||
transformer = self.transformers[resource_type]
|
||||
|
||||
if transformer:
|
||||
properties = {
|
||||
VProps.TYPE: resource_type,
|
||||
VProps.ID: resource_name,
|
||||
VProps.SAMPLE_TIMESTAMP: sample_timestamp
|
||||
}
|
||||
resource_vertex = transformer.create_placeholder_vertex(
|
||||
**properties)
|
||||
|
||||
relationship_edge = graph_utils.create_edge(
|
||||
source_id=vitrage_id,
|
||||
target_id=resource_vertex.vertex_id,
|
||||
relationship_type=EdgeLabel.ON)
|
||||
|
||||
return Neighbor(resource_vertex, relationship_edge)
|
||||
|
||||
LOG.warning('Cannot transform host, host transformer does not exist')
|
||||
return None
|
||||
|
||||
def _ok_status(self, entity_event):
|
||||
return entity_event[ZabbixProperties.STATUS] == ZabbixTriggerStatus.OK
|
||||
|
||||
def _create_entity_key(self, entity_event):
|
||||
|
||||
sync_type = entity_event[DSProps.SYNC_TYPE]
|
||||
alarm_name = entity_event[ZabbixProperties.DESCRIPTION]
|
||||
resource_name = entity_event[ZabbixProperties.RESOURCE_NAME]
|
||||
return tbase.build_key(self._key_values(sync_type,
|
||||
resource_name,
|
||||
alarm_name))
|
@ -38,7 +38,7 @@ class RaiseAlarm(base.Recipe):
|
||||
def get_do_recipe(action_spec):
|
||||
|
||||
params = RaiseAlarm._get_vertex_params(action_spec)
|
||||
params[VProps.STATE] = AlarmProps.ALARM_ACTIVE_STATE
|
||||
params[VProps.STATE] = AlarmProps.ACTIVE_STATE
|
||||
add_vertex_step = ActionStepWrapper(ADD_VERTEX, params)
|
||||
|
||||
return [add_vertex_step]
|
||||
@ -47,7 +47,7 @@ class RaiseAlarm(base.Recipe):
|
||||
def get_undo_recipe(action_spec):
|
||||
|
||||
params = RaiseAlarm._get_vertex_params(action_spec)
|
||||
params[VProps.STATE] = AlarmProps.ALARM_INACTIVE_STATE
|
||||
params[VProps.STATE] = AlarmProps.INACTIVE_STATE
|
||||
remove_vertex_step = ActionStepWrapper(REMOVE_VERTEX, params)
|
||||
|
||||
return [remove_vertex_step]
|
||||
|
@ -164,7 +164,7 @@ class TestActionExecutor(TestFunctionalBase):
|
||||
props = {
|
||||
TFields.ALARM_NAME: 'VM_CPU_SUBOPTIMAL_PERFORMANCE',
|
||||
TFields.SEVERITY: 'CRITICAL',
|
||||
VProps.STATE: AlarmProps.ALARM_ACTIVE_STATE
|
||||
VProps.STATE: AlarmProps.ACTIVE_STATE
|
||||
}
|
||||
|
||||
# Raise alarm action adds new vertex with type vitrage to the graph
|
||||
@ -205,7 +205,7 @@ class TestActionExecutor(TestFunctionalBase):
|
||||
self.assertEqual(alarm.properties[VProps.OPERATIONAL_SEVERITY],
|
||||
props[TFields.SEVERITY])
|
||||
self.assertEqual(alarm.properties[VProps.STATE],
|
||||
AlarmProps.ALARM_ACTIVE_STATE)
|
||||
AlarmProps.ACTIVE_STATE)
|
||||
|
||||
def test_execute_add_and_remove_vertex(self):
|
||||
|
||||
@ -222,7 +222,7 @@ class TestActionExecutor(TestFunctionalBase):
|
||||
props = {
|
||||
TFields.ALARM_NAME: 'VM_CPU_SUBOPTIMAL_PERFORMANCE',
|
||||
TFields.SEVERITY: 'CRITICAL',
|
||||
VProps.STATE: AlarmProps.ALARM_ACTIVE_STATE
|
||||
VProps.STATE: AlarmProps.ACTIVE_STATE
|
||||
}
|
||||
action_spec = ActionSpecs(ActionType.RAISE_ALARM, targets, props)
|
||||
|
||||
|
@ -22,7 +22,7 @@ from vitrage.common.constants import SyncMode
|
||||
from vitrage.common.constants import VertexProperties as VProps
|
||||
from vitrage.datasources.alarm_properties import AlarmProperties as AlarmProps
|
||||
from vitrage.datasources.nagios.properties import NagiosProperties
|
||||
from vitrage.datasources.nagios.properties import NagiosStatus
|
||||
from vitrage.datasources.nagios.properties import NagiosTestStatus
|
||||
from vitrage.datasources.nagios.transformer import NagiosTransformer
|
||||
from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE
|
||||
from vitrage.datasources.nova.host.transformer import HostTransformer
|
||||
@ -110,14 +110,14 @@ class NagiosTransformerTest(base.BaseTest):
|
||||
event_type = event.get(DSProps.EVENT_TYPE, None)
|
||||
if event_type is not None:
|
||||
self.assertEqual(vertex[VProps.STATE],
|
||||
AlarmProps.ALARM_INACTIVE_STATE if
|
||||
AlarmProps.INACTIVE_STATE if
|
||||
EventAction.DELETE_ENTITY == event_type else
|
||||
AlarmProps.ALARM_ACTIVE_STATE)
|
||||
AlarmProps.ACTIVE_STATE)
|
||||
else:
|
||||
self.assertEqual(vertex[VProps.STATE],
|
||||
AlarmProps.ALARM_INACTIVE_STATE if
|
||||
NagiosStatus.OK == event[NagiosProperties.STATUS]
|
||||
else AlarmProps.ALARM_ACTIVE_STATE)
|
||||
actual_state = AlarmProps.INACTIVE_STATE if \
|
||||
NagiosTestStatus.OK == event[NagiosProperties.STATUS] \
|
||||
else AlarmProps.ACTIVE_STATE
|
||||
self.assertEqual(vertex[VProps.STATE], actual_state)
|
||||
|
||||
self.assertEqual(event[NagiosProperties.STATUS],
|
||||
vertex[VProps.SEVERITY])
|
||||
|
15
vitrage/tests/unit/datasources/zabbix/__init__.py
Normal file
15
vitrage/tests/unit/datasources/zabbix/__init__.py
Normal file
@ -0,0 +1,15 @@
|
||||
# Copyright 2016 - Nokia
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
__author__ = 'stack'
|
@ -62,7 +62,7 @@ class RaiseAlarmRecipeTest(base.BaseTest):
|
||||
self.assertEqual(self.target_vertex.vertex_id, target_vitrage_id)
|
||||
|
||||
alarm_state = add_vertex_step_params[TFields.STATE]
|
||||
self.assertEqual(alarm_state, AlarmProperties.ALARM_ACTIVE_STATE)
|
||||
self.assertEqual(alarm_state, AlarmProperties.ACTIVE_STATE)
|
||||
|
||||
def test_get_undo_recipe(self):
|
||||
|
||||
@ -87,4 +87,4 @@ class RaiseAlarmRecipeTest(base.BaseTest):
|
||||
self.assertEqual(self.target_vertex.vertex_id, target_vitrage_id)
|
||||
|
||||
alarm_state = remove_vertex_step_params[TFields.STATE]
|
||||
self.assertEqual(alarm_state, AlarmProperties.ALARM_INACTIVE_STATE)
|
||||
self.assertEqual(alarm_state, AlarmProperties.INACTIVE_STATE)
|
||||
|
Loading…
Reference in New Issue
Block a user