Skip to content

Commit

Permalink
Merge pull request #1532 from naparuba/Fix-module_autogeneration_and_…
Browse files Browse the repository at this point in the history
…module_attribute_type

Fix module autogeneration and module attribute type
  • Loading branch information
titilambert committed Mar 6, 2015
2 parents f9135ea + d23df87 commit 1ff4f93
Show file tree
Hide file tree
Showing 4 changed files with 305 additions and 6 deletions.
12 changes: 6 additions & 6 deletions shinken/objects/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,9 +1112,6 @@ def create_objects_for_type(self, raw_objects, type):
def early_arbiter_linking(self):
""" Prepare the arbiter for early operations """

# Should look at hacking command_file module first
self.hack_old_nagios_parameters_for_arbiter()

if len(self.arbiters) == 0:
logger.warning("There is no arbiter, I add one in localhost:7770")
a = ArbiterLink({'arbiter_name': 'Default-Arbiter',
Expand All @@ -1123,6 +1120,9 @@ def early_arbiter_linking(self):
'spare': '0'})
self.arbiters = ArbiterLinks([a])

# Should look at hacking command_file module first
self.hack_old_nagios_parameters_for_arbiter()

# First fill default
self.arbiters.fill_default()
self.modules.fill_default()
Expand Down Expand Up @@ -1644,7 +1644,7 @@ def got_scheduler_module_type_defined(self, mod_type):
def got_arbiter_module_type_defined(self, mod_type):
for a in self.arbiters:
# Do like the linkify will do after....
for m in getattr(a, 'modules', '').split(','):
for m in getattr(a, 'modules', []):
# So look at what the arbiter try to call as module
m = m.strip()
# Ok, now look in modules...
Expand Down Expand Up @@ -1818,8 +1818,8 @@ def hack_old_nagios_parameters_for_arbiter(self):
for (mod, data) in mod_to_add:
logger.warning("Module %s was autogenerated", data['module_name'])
for a in self.arbiters:
a.modules = ','.join([getattr(a, 'modules', ''), data['module_name']])
self.modules.items[mod.id] = mod
a.modules = getattr(a, 'modules', []) + [data['module_name']]
self.modules.add_item(mod)


# Set our timezone value and give it too to unset satellites
Expand Down
122 changes: 122 additions & 0 deletions test/etc/shinken_module_autogeneration.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
accept_passive_host_checks=1
accept_passive_service_checks=1
additional_freshness_latency=15
admin_email=shinken@localhost
admin_pager=shinken@localhost
auto_reschedule_checks=0
auto_rescheduling_interval=30
auto_rescheduling_window=180
cached_host_check_horizon=15
cached_service_check_horizon=15
cfg_file=standard/hosts.cfg
cfg_file=standard/services.cfg
cfg_file=standard/contacts.cfg
cfg_file=1r_1h_1s/commands.cfg
cfg_file=1r_1h_1s/test_specific.cfg
cfg_file=standard/timeperiods.cfg
cfg_file=standard/hostgroups.cfg
cfg_file=standard/servicegroups.cfg
cfg_file=standard/shinken-specific.cfg
check_external_commands=1
check_for_orphaned_hosts=1
check_for_orphaned_services=1
check_host_freshness=0
check_result_path=var/spool/checkresults
check_result_reaper_frequency=10
check_service_freshness=1
command_check_interval=-1
command_file=var/shinken.cmd
daemon_dumps_core=0
date_format=iso8601
debug_file=var/shinken.debug
debug_level=112
debug_verbosity=1
enable_embedded_perl=0
enable_environment_macros=1
enable_event_handlers=1
enable_flap_detection=0
enable_notifications=1
enable_predictive_host_dependency_checks=1
enable_predictive_service_dependency_checks=1
event_broker_options=-1
event_handler_timeout=30
execute_host_checks=1
execute_service_checks=1
external_command_buffer_slots=4096
high_host_flap_threshold=20
high_service_flap_threshold=20
host_check_timeout=30
host_freshness_check_interval=60
host_inter_check_delay_method=s
illegal_macro_output_chars=`~\$&|'"<>
illegal_object_name_chars=`~!\$%^&*|'"<>?,()=
interval_length=60
lock_file=var/shinken.pid
log_archive_path=var/archives
log_event_handlers=1
log_external_commands=1
log_file=var/shinken.log
log_host_retries=1
log_initial_states=0
log_notifications=1
log_passive_checks=1
log_rotation_method=d
log_service_retries=1
low_host_flap_threshold=5
low_service_flap_threshold=5
max_check_result_file_age=3600
max_check_result_reaper_time=30
max_concurrent_checks=0
max_debug_file_size=1000000
max_host_check_spread=30
max_service_check_spread=30
shinken_group=shinken
shinken_user=shinken
notification_timeout=30
object_cache_file=var/objects.cache
obsess_over_hosts=0
obsess_over_services=0
ocsp_timeout=5
#p1_file=/tmp/test_shinken/plugins/p1.pl
p1_file=/usr/local/shinken/bin/p1.pl
passive_host_checks_are_soft=0
perfdata_timeout=5
precached_object_file=var/objects.precache
process_performance_data=1
resource_file=resource.cfg
retain_state_information=1
retained_contact_host_attribute_mask=0
retained_contact_service_attribute_mask=0
retained_host_attribute_mask=0
retained_process_host_attribute_mask=0
retained_process_service_attribute_mask=0
retained_service_attribute_mask=0
retention_update_interval=60
service_check_timeout=60
service_freshness_check_interval=60
service_inter_check_delay_method=s
service_interleave_factor=s
##shinken_group=shinken
##shinken_user=shinken
#shinken_group=shinken
#shinken_user=shinken
sleep_time=0.25
soft_state_dependencies=0
state_retention_file=var/retention.dat
status_file=var/status.dat
status_update_interval=5
temp_file=tmp/shinken.tmp
temp_path=var/tmp
translate_passive_host_checks=0
use_aggressive_host_checking=0
use_embedded_perl_implicitly=0
use_large_installation_tweaks=0
use_regexp_matching=0
use_retained_program_state=1
use_retained_scheduling_info=1
use_syslog=0
use_true_regexp_matching=0
enable_problem_impacts_states_change=1
no_event_handlers_during_downtimes=0
modules_dir=../var/lib/shinken/modules
command_file=PATH/TO/CMDFILE
137 changes: 137 additions & 0 deletions test/test_end_parsing_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/usr/bin/env python
# Copyright (C) 2009-2015:
# Coavoux Sebastien <s.coavoux@free.fr>
#
# This file is part of Shinken.
#
# Shinken is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Shinken is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Shinken. If not, see <http://www.gnu.org/licenses/>.

#
# This file is used to test reading and processing of config files
#

import unittest2 as unittest

import string

from shinken_test import time_hacker
from shinken.log import logger
from shinken.objects.config import Config
from shinken.brok import Brok
from shinken.external_command import ExternalCommand
from shinken.property import UnusedProp, StringProp, IntegerProp, \
BoolProp, CharProp, DictProp, FloatProp, ListProp, AddrProp, ToGuessProp


class TestEndParsingType(unittest.TestCase):

def map_type(self, obj):
if isinstance(obj, ListProp):
return list

if isinstance(obj, StringProp):
return str

if isinstance(obj, UnusedProp):
return str

if isinstance(obj, BoolProp):
return bool

if isinstance(obj, IntegerProp):
return int

if isinstance(obj, FloatProp):
return float

if isinstance(obj, CharProp):
return str

if isinstance(obj, DictProp):
return dict

if isinstance(obj, AddrProp):
return str

if isinstance(obj, ToGuessProp):
return str

def print_header(self):
print "\n" + "#" * 80 + "\n" + "#" + " " * 78 + "#"
print "#" + string.center(self.id(), 78) + "#"
print "#" + " " * 78 + "#\n" + "#" * 80 + "\n"

def add(self, b):
if isinstance(b, Brok):
self.broks[b.id] = b
return
if isinstance(b, ExternalCommand):
self.sched.run_external_command(b.cmd_line)

def test_types(self):
path = 'etc/shinken_1r_1h_1s.cfg'
time_hacker.set_my_time()
self.print_header()
# i am arbiter-like
self.broks = {}
self.me = None
self.log = logger
self.log.setLevel("INFO")
self.log.load_obj(self)
self.config_files = [path]
self.conf = Config()
buf = self.conf.read_config(self.config_files)
raw_objects = self.conf.read_config_buf(buf)
self.conf.create_objects_for_type(raw_objects, 'arbiter')
self.conf.create_objects_for_type(raw_objects, 'module')
self.conf.early_arbiter_linking()
self.conf.create_objects(raw_objects)
self.conf.instance_id = 0
self.conf.instance_name = 'test'
# Hack push_flavor, that is set by the dispatcher
self.conf.push_flavor = 0
self.conf.load_triggers()
self.conf.linkify_templates()
self.conf.apply_inheritance()
self.conf.explode()

self.conf.apply_implicit_inheritance()
self.conf.fill_default()
self.conf.remove_templates()
self.conf.compute_hash()

self.conf.override_properties()
self.conf.linkify()
self.conf.apply_dependencies()
self.conf.explode_global_conf()
self.conf.propagate_timezone_option()
self.conf.create_business_rules()
self.conf.create_business_rules_dependencies()
self.conf.is_correct()


for arb in self.conf.arbiters:
for prop in arb.properties:
if hasattr(arb, prop):
value = getattr(arb, prop)
# We should get ride of None, maybe use the "neutral" value for type
if value is not None:
#print("TESTING %s with value %s" % (prop, value))
self.assertIsInstance(value, self.map_type(arb.properties[prop]))
else:
print("Skipping %s " % prop)


if __name__ == '__main__':
unittest.main()
40 changes: 40 additions & 0 deletions test/test_module_autogeneration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python
# Copyright (C) 2009-2014:
# Gabes Jean, naparuba@gmail.com
# Gerhard Lausser, Gerhard.Lausser@consol.de
#
# This file is part of Shinken.
#
# Shinken is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Shinken is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Shinken. If not, see <http://www.gnu.org/licenses/>.

#
# This file is used to test reading and processing of config files
#

from shinken_test import *


class TestModuleAutogeneration(ShinkenTest):

def setUp(self):
self.setup_with_file('etc/shinken_module_autogeneration.cfg')

def test_module_autogeneration(self):
modules = [m.module_name for m in self.conf.arbiters[0].modules]
self.assertListEqual(modules, ["NamedPipe-Autogenerated"])



if __name__ == '__main__':
unittest.main()

1 comment on commit 1ff4f93

@naparuba
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Please sign in to comment.