diff --git a/requirements.txt b/requirements.txt index 8692f17fb..341539910 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,7 @@ pbr>=1.6 Babel>=1.3 +lxml>=2.3 python-dateutil>=2.4.2 python-novaclient>=2.26.0 networkx>=1.10 diff --git a/test-requirements.txt b/test-requirements.txt index 288e5f4a3..933e2fba4 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -6,6 +6,7 @@ hacking<0.11,>=0.10.0 python-dateutil>=2.4.2 coverage>=3.6 discover +lxml>=2.3 networkx>=1.10 python-novaclient>=2.26.0 python-subunit>=0.0.18 diff --git a/vitrage/tests/resources/nagios/nagios-mock.html b/vitrage/tests/resources/nagios/nagios-mock.html new file mode 100644 index 000000000..c66236c75 --- /dev/null +++ b/vitrage/tests/resources/nagios/nagios-mock.html @@ -0,0 +1,430 @@ + + + + + +Current Network Status + + + + + + + + + + + + + + + + + + + +
+ + +
+
Current Network Status
+Last Updated: Wed Feb 17 15:22:05 IST 2016
+Updated every 90 seconds
+Nagios® Core™ 3.5.0 - www.nagios.org
+Logged in as nagiosadmin
+
+ + + +
+
Host Status Totals
+ + +
+ + + + + + + + + + + + + +
UpDownUnreachablePending
24200
+
+ + + + + + + + +
All ProblemsAll Types
226
+
+ +
+
Service Status Totals
+ + +
+ + + + + + + + + + + + + + + +
OkWarningUnknownCriticalPending
7427170
+
+ + + + + + + + +
All ProblemsAll Types
15757
+
+ +
+
+ + + + + +
+ +
Service Status Details For All Hosts
+
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Host Sort by host name (ascending)Sort by host name (descending)Service Sort by service name (ascending)Sort by service name (descending)Status Sort by service status (ascending)Sort by service status (descending)Last Check Sort by last check time (ascending)Sort by last check time (descending)Duration Sort by state duration (ascending)Sort by state duration time (descending)Attempt Sort by current attempt (ascending)Sort by current attempt (descending)Status Information
+ + + + +
+ + + + +
compute-0-0.local
+
+ + + + +
Perform Extra Host Actions
+
+
+ +
+ + +
CPU load
+
+ + + + +
Active and passive checks have been disabled for this servicePerform Extra Service Actions
+
WARNING2016-02-09 13:05:32 8d 2h 16m 33s1/1high CPU load 
+ +
+ + +
CPU utilization
+
+ + + + +
Active checks of the service have been disabled - only passive checks are being acceptedPerform Extra Service Actions
+
OK2016-02-17 15:21:2214d 1h 29m 34s1/1OK - user: 0.5%, system: 0.4%, wait: 2.4%, total: 3.3% 
+ +
+ + +
Disk IO SUMMARY
+
+ + + + +
Active checks of the service have been disabled - only passive checks are being acceptedPerform Extra Service Actions
+
OK2016-02-17 15:21:2214d 1h 28m 34s1/1OK - 0.00 B/sec read, 1.84 MB/sec write, IOs: 89.00/sec 
+ + + + +
+ + + + +
compute-0-1.local
+
+ + + + +
Perform Extra Host Actions
+
+
+ +
+ + +
CPU load
+
+ + + + +
Active checks of the service have been disabled - only passive checks are being acceptedPerform Extra Service Actions
+
OK2016-02-17 15:21:22 0d 1h 48m 43s1/1OK - 15min load 1.27 at 24 CPUs 
+ +
+ + +
CPU utilization
+
+ + + + +
Active checks of the service have been disabled - only passive checks are being acceptedPerform Extra Service Actions
+
OK2016-02-17 15:21:2214d 1h 29m 19s1/1OK - user: 0.5%, system: 0.4%, wait: 2.2%, total: 3.1% 
+ +
+ + +
check_load
+
+ + + + +
Active and passive checks have been disabled for this servicePerform Extra Service Actions
+
CRITICAL2016-02-16 14:27:06 1d 0h 54m 59s1/1Critical Error 
+ + + + +
+ + + + +
os-ceilometer-00.local
+
+ + + + +
Perform Extra Host Actions
+
+
+ +
+ + +
CPU load
+
+ + + + +
Active checks of the service have been disabled - only passive checks are being acceptedPerform Extra Service Actions
+
OK2016-02-17 15:21:5114d 0h 48m 4s1/1OK - 15min load 0.36 at 2 CPUs 
+ +
+ + +
CPU utilization
+
+ + + + +
Active checks of the service have been disabled - only passive checks are being acceptedPerform Extra Service Actions
+
OK2016-02-17 15:21:5114d 0h 48m 4s1/1OK - user: 2.7%, system: 1.0%, wait: 0.1%, total: 3.8% 
+ + + + +
+ + + + +
os-ceilometer-01.local
+
+ + + + +
Perform Extra Host Actions
+
+
+ +
+ + +
CPU load
+
+ + + + +
Active checks of the service have been disabled - only passive checks are being acceptedPerform Extra Service Actions
+
OK2016-02-17 15:21:5114d 0h 48m 2s1/1OK - 15min load 0.44 at 2 CPUs 
+ +
+ + +
CPU utilization
+
+ + + + +
Active checks of the service have been disabled - only passive checks are being acceptedPerform Extra Service Actions
+
OK2016-02-17 15:21:5114d 0h 48m 2s1/1OK - user: 2.7%, system: 1.1%, wait: 0.2%, total: 4.1% 
+
Results 1 - 757 of 757 Matching Services
+ + + + + diff --git a/vitrage/tests/unit/synchronizer/nagios/test_nagios_parser.py b/vitrage/tests/unit/synchronizer/nagios/test_nagios_parser.py new file mode 100644 index 000000000..518bb733c --- /dev/null +++ b/vitrage/tests/unit/synchronizer/nagios/test_nagios_parser.py @@ -0,0 +1,88 @@ +# 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.synchronizer.plugins.nagios.parser import NagiosParser +from vitrage.synchronizer.plugins.nagios.properties import NagiosProperties +from vitrage.tests import base +from vitrage.tests.mocks import utils + +LOG = logging.getLogger(__name__) + + +class NagiosParserTest(base.BaseTest): + + expected_service1 = {NagiosProperties.RESOURCE_NAME: 'compute-0-0.local', + NagiosProperties.SERVICE: 'CPU load', + NagiosProperties.STATUS: 'WARNING', + NagiosProperties.LAST_CHECK: '2016-02-09 13:05:32', + NagiosProperties.DURATION: ' 8d 2h 16m 33s', + NagiosProperties.ATTEMPT: '1/1', + NagiosProperties.STATUS_INFO: + u'high CPU load\xa0'} + + expected_service2 = {NagiosProperties.RESOURCE_NAME: 'compute-0-1.local', + NagiosProperties.SERVICE: 'check_load', + NagiosProperties.STATUS: 'CRITICAL', + NagiosProperties.LAST_CHECK: '2016-02-16 14:27:06', + NagiosProperties.DURATION: ' 1d 0h 54m 59s', + NagiosProperties.ATTEMPT: '1/1', + NagiosProperties.STATUS_INFO: + u'Critical Error\xa0'} + + expected_service3 = {NagiosProperties.RESOURCE_NAME: 'compute-0-0.local', + NagiosProperties.SERVICE: 'Disk IO SUMMARY', + NagiosProperties.STATUS: 'OK', + NagiosProperties.LAST_CHECK: '2016-02-17 15:21:22', + NagiosProperties.DURATION: '14d 1h 28m 34s', + NagiosProperties.ATTEMPT: '1/1', + NagiosProperties.STATUS_INFO: + u'OK - 0.00 B/sec read, 1.84 MB/sec write, ' + u'IOs: 89.00/sec\xa0'} + + def setUp(self): + super(NagiosParserTest, self).setUp() + + def test_template_loader(self): + # Setup + fp = open(utils.get_resources_dir() + '/nagios/nagios-mock.html') + nagios_html = fp.read() + + # Action + nagios_services = NagiosParser().parse(nagios_html) + + # Test assertions + self.assertTrue(nagios_services) + self._assert_contains(nagios_services, self.expected_service1) + self._assert_contains(nagios_services, self.expected_service2) + self._assert_contains(nagios_services, self.expected_service3) + + def _assert_contains(self, services, expected_service): + for service in services: + if service[NagiosProperties.RESOURCE_NAME] == \ + expected_service[NagiosProperties.RESOURCE_NAME] and \ + service[NagiosProperties.SERVICE] == \ + expected_service[NagiosProperties.SERVICE]: + self._assert_expected_service(expected_service, service) + return + + self.fail("service not found: %(resource_name)s %(service_name)s" % + {'resource_name': + expected_service[NagiosProperties.RESOURCE_NAME], + 'service_name': + expected_service[NagiosProperties.SERVICE]}) + + def _assert_expected_service(self, expected_service, service): + for key, value in expected_service.items(): + self.assertEqual(value, service[key], 'wrong value for ' + key)