Skip to content

Commit

Permalink
Temporary push for save commit!
Browse files Browse the repository at this point in the history
  • Loading branch information
Frédéric Mohier committed Jun 7, 2019
1 parent dc67a87 commit 847ce0e
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 103 deletions.
16 changes: 10 additions & 6 deletions alignak/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
import sys
import time
import json
import tempfile
import resource
import socket
import signal
Expand Down Expand Up @@ -652,12 +653,6 @@ def __init__(self, name, **kwargs):
else:
print("Daemon '%s' log file: %s" % (self.name, self.log_filename))

# Check the log directory (and create if it does not exist)
# self.check_dir(os.path.dirname(self.log_filename))

# Specific monitoring log directory
# self.check_dir(os.path.join(os.path.dirname(self.log_filename), 'monitoring-log'))

if 'log_filename' not in kwargs or not kwargs['log_filename']:
# Log file name is not overridden, the logger will use the configured default one
if self.log_cherrypy:
Expand Down Expand Up @@ -807,6 +802,10 @@ def check_dir(self, dir_name, create):
relative to the working directory. It will return the full path of the
directory
If the daemon is in very mode (arbiter -V command line) and the directory
cannot be created, then this function will return the system temporary files
directory
:param create: create if it does not exist
:type create: bool
Expand Down Expand Up @@ -855,6 +854,11 @@ def check_dir(self, dir_name, create):
return dir_name

except OSError as exp:
if self.verify_only and exp.errno == 13:
# In verify mode, forward directory to the /tmp
print("Exception: %s" % exp)
return tempfile.gettempdir()

if exp.errno == errno.EEXIST and os.path.isdir(dir_name):
# Directory still exists...
pass
Expand Down
8 changes: 5 additions & 3 deletions alignak/daemons/arbiterdaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ def __init__(self, **kwargs):
self.my_monitor = None
self.my_status = 0

# Verify mode is set thanks to the -V command line parameter
self.verify_only = False
if 'verify_only' in kwargs and kwargs['verify_only']:
self.verify_only = kwargs.get('verify_only', False)

super(Arbiter, self).__init__(kwargs.get('daemon_name', 'Default-Arbiter'), **kwargs)

# Our schedulers and arbiters are initialized in the base class
Expand Down Expand Up @@ -159,9 +164,6 @@ def __init__(self, **kwargs):
my_cfg_files.append(os.path.abspath(cfg_file))
self.legacy_cfg_files = my_cfg_files

self.verify_only = False
if 'verify_only' in kwargs and kwargs['verify_only']:
self.verify_only = kwargs.get('verify_only', False)
self.alignak_name = self.name
if 'alignak_name' in kwargs and kwargs['alignak_name']:
self.alignak_name = kwargs['alignak_name']
Expand Down
20 changes: 0 additions & 20 deletions alignak/objects/checkmodulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,23 +161,3 @@ def linkify(self, timeperiods, commands):
"""
self.linkify_with_timeperiods(timeperiods, 'check_period')
self.linkify_with_commands(commands, 'check_command')

def new_inner_member(self, name=None, params=None):
"""Create a CheckModulation object and add it to items
:param name: CheckModulation name
:type name: str
:param params: parameters to init CheckModulation
:type params: dict
:return: None
TODO: Remove this default mutable argument. Usually result in unexpected behavior
"""
if name is None:
name = 'Generated_checkmodulation_%s' % uuid.uuid4()

if params is None:
params = {}

params['checkmodulation_name'] = name
checkmodulation = CheckModulation(params)
self.add_item(checkmodulation)
60 changes: 32 additions & 28 deletions alignak/objects/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"""
import logging
from alignak.objects.item import Item
from alignak.objects.notificationway import NotificationWay
from alignak.objects.commandcallitem import CommandCallItems

from alignak.util import strip_and_uniq
Expand Down Expand Up @@ -173,13 +174,6 @@ class Contact(Item):
'contact_name'
)

simple_way_parameters = (
'service_notification_period', 'host_notification_period',
'service_notification_options', 'host_notification_options',
'service_notification_commands', 'host_notification_commands',
'min_business_impact'
)

def __init__(self, params, parsing=True):
# When deserialized, those are dict
for prop in ['service_notification_commands', 'host_notification_commands']:
Expand Down Expand Up @@ -326,8 +320,8 @@ def want_host_notification(self, notifways, timeperiods, timestamp, state, n_typ
def get_notification_commands(self, notifways, n_type, command_name=False):
"""Get notification commands for object type
:param notifways: list of alignak.objects.NotificationWay objects
:type notifways: NotificationWays
:param notifways: list of notification ways objects
:type notifways: alignak.objects.notificationway.NotificationWays
:param n_type: object type (host or service)
:type n_type: string
:param command_name: True to update the inner property with the name of the command,
Expand All @@ -343,10 +337,9 @@ def get_notification_commands(self, notifways, n_type, command_name=False):
res.extend(notifway.get_notification_commands(n_type))

# Update inner notification commands property with command name or command
setattr(self, n_type + '_notification_commands', res)
if command_name:
setattr(self, n_type + '_notification_commands', [c.get_name() for c in res])
else:
setattr(self, n_type + '_notification_commands', res)

return res

Expand Down Expand Up @@ -505,26 +498,37 @@ def explode(self, contactgroups, notificationways):
for contactgroup in contact.contactgroups:
contactgroups.add_member(contact.contact_name, contactgroup.strip())

# Now create a notification way with the simple parameter of the
# contacts
# Now create a notification way with the simple parameter of the contacts
for contact in self:
need_notificationway = False
# Fill default values for all the properties
contact.fill_default()
print("Contact: %s" % contact)

add_nw = False
params = {}
for param in Contact.simple_way_parameters:
for param in ['service_notification_period', 'host_notification_period',
'service_notification_options', 'host_notification_options',
'service_notification_commands', 'host_notification_commands',
'min_business_impact']:
if hasattr(contact, param):
need_notificationway = True
add_nw = True
params[param] = getattr(contact, param)
elif contact.properties[param].has_default: # put a default text value
# Remove the value and put a default value
setattr(contact, param, contact.properties[param].default)
# elif contact.properties[param].has_default: # put a default text value
# # Remove the value and put a default value
# setattr(contact, param, contact.properties[param].default)

if need_notificationway:
cname = getattr(contact, 'contact_name', getattr(contact, 'alias', ''))
nw_name = cname + '_inner_nw'
notificationways.new_inner_member(nw_name, params)
if not add_nw:
continue

if not hasattr(contact, 'notificationways'):
contact.notificationways = [nw_name]
else:
contact.notificationways = list(contact.notificationways)
contact.notificationways.append(nw_name)
cname = getattr(contact, 'contact_name', getattr(contact, 'alias', ''))
cname = contact.get_name()
params['notificationway_name'] = cname + '_inner_nw'
# notificationways.new_inner_member(nw_name, params)
print("-> nw: %s" % params)
notificationways.add_item(NotificationWay(params, parsing=True))

if not hasattr(contact, 'notificationways'):
contact.notificationways = [params['notificationway_name']]
else:
contact.notificationways = list(contact.notificationways)
contact.notificationways.append(params['notificationway_name'])
53 changes: 26 additions & 27 deletions alignak/objects/notificationway.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"""
import logging
from alignak.objects.item import Item
from alignak.misc.serialization import serialize, unserialize
from alignak.objects.commandcallitem import CommandCallItems

from alignak.property import BoolProp, IntegerProp, StringProp, ListProp, FULL_STATUS
Expand Down Expand Up @@ -108,26 +109,33 @@ class NotificationWay(Item):
'service_notification_period', 'host_notification_period')

def __init__(self, params, parsing=True):
# When deserialized, those are dict
print("NW, parsing: %s, params: %s" % (parsing, params))
for prop in ['service_notification_commands', 'host_notification_commands']:
if prop in params and isinstance(params[prop], list) and params[prop] \
and isinstance(params[prop][0], dict):
new_list = [CommandCall(elem, parsing=parsing) for elem in params[prop]]
if prop not in params or params[prop] is None:
continue
if not parsing:
# When deserialized, those are dict and we recreate the object
setattr(self, prop, [unserialize(elem) for elem in params[prop]])
else:
new_list = [(CommandCall(elem, parsing=parsing) if isinstance(elem, dict) else
elem) for elem in params[prop]]
# We recreate the object
setattr(self, prop, new_list)
# And remove prop, to prevent from being overridden
del params[prop]
# And remove prop, to prevent from being overridden
del params[prop]

super(NotificationWay, self).__init__(params, parsing=parsing)
# self.fill_default()
print("NW: %s" % self.__dict__)

def serialize(self):
res = super(NotificationWay, self).serialize()

for prop in ['service_notification_commands', 'host_notification_commands']:
if getattr(self, prop) is None:
res[prop] = None
else:
res[prop] = [elem.serialize() for elem in getattr(self, prop)]
res['service_notification_commands'] = \
[elem.serialize() for elem in getattr(self, 'service_notification_commands')]

res['host_notification_commands'] = \
[elem.serialize() for elem in getattr(self, 'host_notification_commands')]

return res

Expand Down Expand Up @@ -266,9 +274,12 @@ def get_notification_commands(self, o_type):
:rtype: list[alignak.objects.command.Command]
"""
# service_notification_commands for service
notif_commands_prop = o_type + '_notification_commands'
notif_commands = getattr(self, notif_commands_prop)
return notif_commands
# print("... %s / %s" % (o_type, getattr(self, o_type + '_notification_commands', [])))
# print("... %s" % (self.__dict__))
commands = getattr(self, o_type + '_notification_commands', []) or []
# if commands is None:
# commands = []
return commands

def is_correct(self):
# pylint: disable=too-many-branches
Expand All @@ -281,6 +292,7 @@ def is_correct(self):
:rtype: bool
"""
state = True
print("Check: %s" % self.__dict__)

# Do not execute checks if notifications are disabled
if (hasattr(self, 'service_notification_options') and
Expand Down Expand Up @@ -354,16 +366,3 @@ def linkify(self, timeperiods, commands):
is_a_list=True)
self.linkify_with_commands(commands, 'host_notification_commands',
is_a_list=True)

def new_inner_member(self, name, params):
"""Create new instance of NotificationWay with given name and parameters
and add it to the item list
:param name: notification way name
:type name: str
:param params: notification wat parameters
:type params: dict
:return: None
"""
params['notificationway_name'] = name
self.add_item(NotificationWay(params))
12 changes: 6 additions & 6 deletions docker/data/alignak/etc/alignak.d/daemons.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ name=arbiter-master
;host=127.0.0.1
; Set the host to 0.0.0.0 to allow Arbiter WS access from another system
port=7770
; My adress for the other daemons
; My address for the other daemons
;address=127.0.0.1

; Modules
Expand All @@ -42,7 +42,7 @@ name=scheduler-master
; My listening interface
;host=127.0.0.1
port=7768
; My adress for the other daemons
; My address for the other daemons
;address=127.0.0.1

; Modules
Expand Down Expand Up @@ -70,7 +70,7 @@ name=poller-master
; My listening interface
;host=127.0.0.1
port=7771
; My adress for the other daemons
; My address for the other daemons
;address=127.0.0.1

; Modules
Expand Down Expand Up @@ -114,7 +114,7 @@ name=reactionner-master
; My listening interface
;host=127.0.0.1
port=7769
; My adress for the other daemons
; My address for the other daemons
;address=127.0.0.1

; Modules
Expand Down Expand Up @@ -156,7 +156,7 @@ name=broker-master
; My listening interface
;host=127.0.0.1
port=7772
; My adress for the other daemons
; My address for the other daemons
;address=127.0.0.1

; Advanced parameters:
Expand Down Expand Up @@ -187,7 +187,7 @@ name=receiver-master
; My listening interface
;host=127.0.0.1
port=7773
; My adress for the other daemons
; My address for the other daemons
;address=127.0.0.1

; Modules
Expand Down
4 changes: 2 additions & 2 deletions docker/data/alignak/etc/base/templates/generic-contact.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ define contact{
# else the default created notification ways raise a configuration error!
service_notification_period 24x7
host_notification_period 24x7
host_notification_commands notify-host-by-log
service_notification_commands notify-service-by-log
# # # host_notification_commands notify-host-by-log
# # # service_notification_commands notify-service-by-log

# Only useful for the UI...
# Change this default password!!!
Expand Down
2 changes: 1 addition & 1 deletion docker/data/alignak/etc/realms/North/contacts/contacts.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
define contact{
use north-contact
contact_name north-admin
alias Administrateur europe
alias Administrateur North

contactgroups admins

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
define hostgroup{
hostgroup_name north-routers
alias North routers

realm North
#members
}

define hostgroup{
hostgroup_name north
alias North hosts

realm North
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
define hostgroup{
hostgroup_name south-routers
alias South routers

realm South
#members
}

define hostgroup{
hostgroup_name south
alias South hosts

realm South
}
Loading

0 comments on commit 847ce0e

Please sign in to comment.