Skip to content

Commit

Permalink
Merge pull request #1461 from gst/test_clean_out_nagios
Browse files Browse the repository at this point in the history
Clean: tests: cleaned out "nagios" things.
  • Loading branch information
gst committed Jan 23, 2015
2 parents dc16d18 + e36b280 commit 98939df
Showing 1 changed file with 0 additions and 159 deletions.
159 changes: 0 additions & 159 deletions test/shinken_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ def do_load_modules(self):
self.modules_manager.load_and_init()
self.log.log("I correctly loaded the modules: [%s]" % (','.join([inst.get_name() for inst in self.modules_manager.instances])))



def update_broker(self, dodeepcopy=False):
# The brok should be manage in the good order
ids = self.sched.brokers['Default-Broker']['broks'].keys()
Expand All @@ -68,7 +66,6 @@ def update_broker(self, dodeepcopy=False):
self.livestatus_broker.manage_brok(brok)
self.sched.brokers['Default-Broker']['broks'] = {}


def init_livestatus(self, modconf=None, dbmodconf=None, needcache=False):
self.livelogs = 'tmp/livelogs.db' + self.testid

Expand Down Expand Up @@ -135,7 +132,6 @@ def init_livestatus(self, modconf=None, dbmodconf=None, needcache=False):
class TestConfig(ShinkenModulesTest):

def tearDown(self):
self.stop_nagios()
self.livestatus_broker.db.close()
if os.path.exists(self.livelogs):
os.remove(self.livelogs)
Expand All @@ -159,11 +155,6 @@ def contains_line(self, text, pattern):
return True
return False

def scheduler_loop(self, count, reflist, do_sleep=False, sleep_time=61):
super(TestConfig, self).scheduler_loop(count, reflist, do_sleep, sleep_time)
if self.nagios_installed() and hasattr(self, 'nagios_started'):
self.nagios_loop(1, reflist)

def update_broker(self, dodeepcopy=False):
# The brok should be manage in the good order
ids = self.sched.brokers['Default-Broker']['broks'].keys()
Expand Down Expand Up @@ -228,154 +219,4 @@ def show_broks(self, title):
response, keepalive = self.livestatus_broker.livestatus.handle_request(request)
print response

def nagios_installed(self, path='/usr/local/nagios/bin/nagios', livestatus='/usr/local/nagios/lib/mk-livestatus/livestatus.o'):
return False
raise
if os.path.exists(path) and os.access(path, os.X_OK) and os.path.exists(livestatus):
self.nagios_path = path
self.livestatus_path = livestatus
return True
else:
return False

# shinkenize_nagios_config('nagios_1r_1h_1s')
# We assume that there is a nagios_1r_1h_1s.cfg and a nagios_1r_1h_1s directory for the objects
def unshinkenize_config(self, configname):
new_configname = configname + '_' + str(os.getpid())
config = open('etc/shinken_' + configname + '.cfg')
text = config.readlines()
config.close()

newconfig = open('etc/shinken_' + new_configname + '.cfg', 'w')
for line in text:
if re.search('^resource_file=', line):
newconfig.write("resource_file=etc/resource.cfg\n")
elif re.search('shinken\-specific\.cfg', line):
pass
elif re.search('enable_problem_impacts_states_change', line):
pass
elif re.search('cfg_dir=', line):
newconfig.write(re.sub(configname, new_configname, line))
elif re.search('cfg_file=', line):
newconfig.write(re.sub(configname, new_configname, line))
elif re.search('execute_host_checks=', line):
newconfig.write("execute_host_checks=0\n")
elif re.search('execute_service_checks=', line):
newconfig.write("execute_service_checks=0\n")
elif re.search('^debug_level=', line):
newconfig.write("debug_level=0\n")
elif re.search('^debug_verbosity=', line):
newconfig.write("debug_verbosity=0\n")
elif re.search('^status_update_interval=', line):
newconfig.write("status_update_interval=30\n")
elif re.search('^command_file=', line):
newconfig.write("command_file=var/shinken.cmd\n")
elif re.search('^command_check_interval=', line):
newconfig.write("command_check_interval=1s\n")
else:
newconfig.write(line)
newconfig.write('broker_module=/usr/local/nagios/lib/mk-livestatus/livestatus.o var/live' + "\n")
newconfig.close()
for dirfile in os.walk('etc/' + configname):
dirpath, dirlist, filelist = dirfile
newdirpath = re.sub(configname, new_configname, dirpath)
os.mkdir(newdirpath)
for file in [f for f in filelist if re.search('\.cfg$', f)]:
config = open(dirpath + '/' + file)
text = config.readlines()
config.close()
newconfig = open(newdirpath + '/' + file, 'w')
for line in text:
if re.search('^\s*criticity', line):
pass
elif re.search('^\s*business_impact', line):
pass
elif re.search('enable_problem_impacts_states_change', line):
pass
else:
newconfig.write(line)
newconfig.close()
return new_configname

def start_nagios(self, config):
if os.path.exists('var/spool/checkresults'):
# Cleanup leftover checkresults
shutil.rmtree('var/spool/checkresults')
for dir in ['tmp', 'var/tmp', 'var/spool', 'var/spool/checkresults', 'var/archives']:
if not os.path.exists(dir):
os.mkdir(dir)
self.nagios_config = self.unshinkenize_config(config)
if os.path.exists('var/shinken.log'):
os.remove('var/shinken.log')
if os.path.exists('var/retention.dat'):
os.remove('var/retention.dat')
if os.path.exists('var/status.dat'):
os.remove('var/status.dat')
self.nagios_proc = subprocess.Popen([self.nagios_path, 'etc/shinken_' + self.nagios_config + '.cfg'], close_fds=True)
self.nagios_started = time.time()
time.sleep(2)

def stop_nagios(self):
if self.nagios_installed():
print "i stop nagios!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
time.sleep(5)
if hasattr(self, 'nagios_proc'):
attempt = 1
while self.nagios_proc.poll() is None and attempt < 4:
self.nagios_proc.terminate()
attempt += 1
time.sleep(1)
if self.nagios_proc.poll() is None:
self.nagios_proc.kill()
if os.path.exists('etc/' + self.nagios_config):
shutil.rmtree('etc/' + self.nagios_config)
if os.path.exists('etc/shinken_' + self.nagios_config + '.cfg'):
os.remove('etc/shinken_' + self.nagios_config + '.cfg')

def ask_nagios(self, request):
if time.time() - self.nagios_started < 2:
time.sleep(1)
if not request.endswith("\n"):
request = request + "\n"
unixcat = subprocess.Popen([os.path.dirname(self.nagios_path) + '/' + 'unixcat', 'var/live'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
tic = time.clock()
out, err = unixcat.communicate(request)
tac = time.clock()
print "mklivestatus duration %f" % (tac - tic)
attempt = 1
while unixcat.poll() is None and attempt < 4:
unixcat.terminate()
attempt += 1
time.sleep(1)
if unixcat.poll() is None:
unixcat.kill()
print "unixcat says", out
return out

def nagios_loop(self, count, reflist, do_sleep=False, sleep_time=61):
now = time.time()
buffer = open('var/pipebuffer', 'w')
for ref in reflist:
(obj, exit_status, output) = ref
if obj.my_type == 'service':
cmd = "[%lu] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n" % (now, obj.host_name, obj.service_description, exit_status, output)
print cmd
buffer.write(cmd)
else:
cmd = "[%lu] PROCESS_HOST_CHECK_RESULT;%s;%d;%s\n" % (now, obj.host_name, exit_status, output)
buffer.write(cmd)
buffer.close()
print "open pipe", self.conf.command_file
fifo = open('var/shinken.cmd', 'w')
cmd = "[%lu] PROCESS_FILE;%s;0\n" % (now, 'var/pipebuffer')
fifo.write(cmd)
fifo.flush()
fifo.close()
time.sleep(5)

def nagios_extcmd(self, cmd):
fifo = open('var/shinken.cmd', 'w')
fifo.write(cmd)
fifo.flush()
fifo.close()
time.sleep(5)

0 comments on commit 98939df

Please sign in to comment.