Changed comma-separated stringfields to lists
Change-Id: I8c2ad414d300357a80652e495f4fb7da28ab401c
This commit is contained in:
parent
2e3a5d6a6b
commit
da45205cb0
@ -7,9 +7,6 @@ RUN apt-get update && apt-get install -y vim python-pip python3-pip python-dev l
|
|||||||
# VirtualEnv
|
# VirtualEnv
|
||||||
RUN virtualenv /opt/surveil/env
|
RUN virtualenv /opt/surveil/env
|
||||||
|
|
||||||
# Surveil needs alignak (as a lib)
|
|
||||||
RUN useradd alignak && /opt/surveil/env/bin/pip install pycurl https://github.com/Alignak-monitoring/alignak/archive/d7f457d5ed94f08d9a6a38809106d3e0d35a1712.tar.gz
|
|
||||||
|
|
||||||
# Download packs
|
# Download packs
|
||||||
ENV MONITORING_TOOLS_VERSION 0.4.0
|
ENV MONITORING_TOOLS_VERSION 0.4.0
|
||||||
RUN apt-get install -y subversion && \
|
RUN apt-get install -y subversion && \
|
||||||
|
@ -10,7 +10,7 @@ keystonemiddleware
|
|||||||
PasteDeploy
|
PasteDeploy
|
||||||
influxdb==2.6.0
|
influxdb==2.6.0
|
||||||
pika
|
pika
|
||||||
python-surveilclient==0.10.0
|
python-surveilclient==0.12.0
|
||||||
six
|
six
|
||||||
docker-py
|
docker-py
|
||||||
mongoengine
|
mongoengine
|
||||||
|
@ -16,6 +16,7 @@ console_scripts =
|
|||||||
surveil-pack-upload = surveil.cmd.pack_upload:main
|
surveil-pack-upload = surveil.cmd.pack_upload:main
|
||||||
surveil-os-discovery = surveil.cmd.os_discovery:main
|
surveil-os-discovery = surveil.cmd.os_discovery:main
|
||||||
surveil-os-interface = surveil.cmd.surveil_os_interface:main
|
surveil-os-interface = surveil.cmd.surveil_os_interface:main
|
||||||
|
surveil-from-nagios = surveil.cmd.surveil_from_nagios:main
|
||||||
|
|
||||||
[build_sphinx]
|
[build_sphinx]
|
||||||
source-dir = doc/source
|
source-dir = doc/source
|
||||||
|
@ -19,11 +19,11 @@ from surveil.api.datamodel import types
|
|||||||
|
|
||||||
|
|
||||||
class BusinessImpactModulation(types.Base):
|
class BusinessImpactModulation(types.Base):
|
||||||
business_impact_modulation_name = wsme.wsattr(wtypes.text, mandatory=True)
|
business_impact_modulation_name = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
|
|
||||||
business_impact = wsme.wsattr(int, mandatory=True)
|
business_impact = wsme.wsattr(int, mandatory=False)
|
||||||
|
|
||||||
modulation_period = wsme.wsattr(wtypes.text, mandatory=True)
|
modulation_period = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def sample(cls):
|
def sample(cls):
|
||||||
|
@ -19,11 +19,11 @@ from surveil.api.datamodel import types
|
|||||||
|
|
||||||
|
|
||||||
class CheckModulation(types.Base):
|
class CheckModulation(types.Base):
|
||||||
checkmodulation_name = wsme.wsattr(wtypes.text, mandatory=True)
|
checkmodulation_name = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
|
|
||||||
check_command = wsme.wsattr(wtypes.text, mandatory=True)
|
check_command = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
|
|
||||||
check_period = wsme.wsattr(wtypes.text, mandatory=True)
|
check_period = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def sample(cls):
|
def sample(cls):
|
||||||
|
@ -27,10 +27,10 @@ from surveil.api.datamodel import types
|
|||||||
|
|
||||||
|
|
||||||
class Command(types.Base):
|
class Command(types.Base):
|
||||||
command_name = wsme.wsattr(wtypes.text, mandatory=True)
|
command_name = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
"""The name of the command"""
|
"""The name of the command"""
|
||||||
|
|
||||||
command_line = wsme.wsattr(wtypes.text, mandatory=True)
|
command_line = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
"""This directive is used to define what is actually executed by Shinken"""
|
"""This directive is used to define what is actually executed by Shinken"""
|
||||||
|
|
||||||
module_type = wsme.wsattr(wtypes.text, mandatory=False)
|
module_type = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
|
@ -19,7 +19,7 @@ from surveil.api.datamodel import types
|
|||||||
|
|
||||||
|
|
||||||
class Contact(types.Base):
|
class Contact(types.Base):
|
||||||
contact_name = wsme.wsattr(wtypes.text, mandatory=True)
|
contact_name = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
|
|
||||||
host_notifications_enabled = wsme.wsattr(int, mandatory=False)
|
host_notifications_enabled = wsme.wsattr(int, mandatory=False)
|
||||||
|
|
||||||
@ -29,13 +29,17 @@ class Contact(types.Base):
|
|||||||
|
|
||||||
service_notification_period = wsme.wsattr(wtypes.text, mandatory=False)
|
service_notification_period = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
|
|
||||||
host_notification_options = wsme.wsattr(wtypes.text, mandatory=False)
|
host_notification_options = wsme.wsattr(wtypes.ArrayType(wtypes.text),
|
||||||
|
mandatory=False)
|
||||||
|
|
||||||
service_notification_options = wsme.wsattr(wtypes.text, mandatory=False)
|
service_notification_options = wsme.wsattr(wtypes.ArrayType(wtypes.text),
|
||||||
|
mandatory=False)
|
||||||
|
|
||||||
host_notification_commands = wsme.wsattr(wtypes.text, mandatory=False)
|
host_notification_commands = wsme.wsattr(wtypes.ArrayType(wtypes.text),
|
||||||
|
mandatory=False)
|
||||||
|
|
||||||
service_notification_commands = wsme.wsattr(wtypes.text, mandatory=False)
|
service_notification_commands = wsme.wsattr(wtypes.ArrayType(wtypes.text),
|
||||||
|
mandatory=False)
|
||||||
|
|
||||||
email = wsme.wsattr(wtypes.text, mandatory=False)
|
email = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
|
|
||||||
|
@ -19,15 +19,21 @@ from surveil.api.datamodel import types
|
|||||||
|
|
||||||
|
|
||||||
class ContactGroup(types.Base):
|
class ContactGroup(types.Base):
|
||||||
contactgroup_name = wsme.wsattr(wtypes.text, mandatory=True)
|
contactgroup_name = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
members = wsme.wsattr(wtypes.text, mandatory=False)
|
members = wsme.wsattr(wtypes.ArrayType(wtypes.text),
|
||||||
|
mandatory=False)
|
||||||
alias = wsme.wsattr(wtypes.text, mandatory=False)
|
alias = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
contactgroup_members = wsme.wsattr(wtypes.text, mandatory=False)
|
contactgroup_members = wsme.wsattr(wtypes.ArrayType(wtypes.text),
|
||||||
|
mandatory=False)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def sample(cls):
|
def sample(cls):
|
||||||
return cls(
|
return cls(
|
||||||
contactgroup_name='novell-admins',
|
contactgroup_name='novell-admins',
|
||||||
alias='Novell Administrators',
|
alias='Novell Administrators',
|
||||||
members='jdoe,rtobert,tzach'
|
members=[
|
||||||
|
'jdoe',
|
||||||
|
'rtobert',
|
||||||
|
'tzach'
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
@ -19,7 +19,7 @@ from surveil.api.datamodel import types
|
|||||||
|
|
||||||
|
|
||||||
class Host(types.Base):
|
class Host(types.Base):
|
||||||
host_name = wsme.wsattr(wtypes.text, mandatory=True)
|
host_name = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
"""The name of the host"""
|
"""The name of the host"""
|
||||||
|
|
||||||
address = wsme.wsattr(wtypes.text, mandatory=False)
|
address = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
@ -30,21 +30,23 @@ class Host(types.Base):
|
|||||||
check_period = wsme.wsattr(wtypes.text, mandatory=False)
|
check_period = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
"""The time period during which active checks of this host can be made."""
|
"""The time period during which active checks of this host can be made."""
|
||||||
|
|
||||||
contacts = wsme.wsattr(wtypes.text, mandatory=False)
|
contacts = wsme.wsattr(wtypes.ArrayType(wtypes.text), mandatory=False)
|
||||||
"""A list of the short names of the contacts that should be notified."""
|
"""A list of the short names of the contacts that should be notified."""
|
||||||
|
|
||||||
contact_groups = wsme.wsattr(wtypes.text, mandatory=False)
|
contact_groups = wsme.wsattr(wtypes.ArrayType(wtypes.text),
|
||||||
"""List of the short names of the contact groups that should be notified"""
|
mandatory=False)
|
||||||
|
"""List of the short names of contact groups that should be notified"""
|
||||||
|
|
||||||
notification_interval = wsme.wsattr(int, mandatory=False)
|
notification_interval = wsme.wsattr(int, mandatory=False)
|
||||||
|
|
||||||
notification_period = wsme.wsattr(wtypes.text, mandatory=False)
|
notification_period = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
|
|
||||||
use = wsme.wsattr(wtypes.text, mandatory=False)
|
use = wsme.wsattr(wtypes.ArrayType(wtypes.text), mandatory=False)
|
||||||
"""The template to use for this host"""
|
"""The template to use for this host"""
|
||||||
|
|
||||||
name = wsme.wsattr(wtypes.text, mandatory=False)
|
name = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
|
|
||||||
|
# TODO(aviau): int!
|
||||||
register = wsme.wsattr(wtypes.text, mandatory=False)
|
register = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
|
|
||||||
check_interval = wsme.wsattr(int, mandatory=False)
|
check_interval = wsme.wsattr(int, mandatory=False)
|
||||||
@ -61,13 +63,14 @@ class Host(types.Base):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def sample(cls):
|
def sample(cls):
|
||||||
return cls(
|
return cls(
|
||||||
use="generic-host",
|
use=["generic-host"],
|
||||||
host_name="bogus-router",
|
host_name="bogus-router",
|
||||||
address="192.168.1.254",
|
address="192.168.1.254",
|
||||||
max_check_attempts=5,
|
max_check_attempts=5,
|
||||||
check_period="24x7",
|
check_period="24x7",
|
||||||
contacts="admin,carl",
|
contacts=["admin",
|
||||||
contact_groups="router-admins",
|
"carl"],
|
||||||
|
contact_groups=["router-admins"],
|
||||||
notification_interval=30,
|
notification_interval=30,
|
||||||
notification_period="24x7",
|
notification_period="24x7",
|
||||||
custom_fields={"OS_AUTH_URL": "http://localhost:8080/v2"}
|
custom_fields={"OS_AUTH_URL": "http://localhost:8080/v2"}
|
||||||
|
@ -19,10 +19,11 @@ from surveil.api.datamodel import types
|
|||||||
|
|
||||||
|
|
||||||
class HostGroup(types.Base):
|
class HostGroup(types.Base):
|
||||||
hostgroup_name = wsme.wsattr(wtypes.text, mandatory=True)
|
hostgroup_name = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
members = wsme.wsattr(wtypes.text, mandatory=False)
|
members = wsme.wsattr(wtypes.ArrayType(wtypes.text), mandatory=False)
|
||||||
alias = wsme.wsattr(wtypes.text, mandatory=False)
|
alias = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
hostgroup_members = wsme.wsattr(wtypes.text, mandatory=False)
|
hostgroup_members = wsme.wsattr(wtypes.ArrayType(wtypes.text),
|
||||||
|
mandatory=False)
|
||||||
notes = wsme.wsattr(wtypes.text, mandatory=False)
|
notes = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
notes_url = wsme.wsattr(wtypes.text, mandatory=False)
|
notes_url = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
action_url = wsme.wsattr(wtypes.text, mandatory=False)
|
action_url = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
@ -32,5 +33,8 @@ class HostGroup(types.Base):
|
|||||||
return cls(
|
return cls(
|
||||||
hostgroup_name='dbservices',
|
hostgroup_name='dbservices',
|
||||||
alias='Novell Servers',
|
alias='Novell Servers',
|
||||||
members='netware1,netware2,netware3,netware4'
|
members=['netware1',
|
||||||
|
'netware2',
|
||||||
|
'netware3',
|
||||||
|
'netware4']
|
||||||
)
|
)
|
||||||
|
@ -19,8 +19,8 @@ from surveil.api.datamodel import types
|
|||||||
|
|
||||||
|
|
||||||
class MacroModulation(types.Base):
|
class MacroModulation(types.Base):
|
||||||
macromodulation_name = wsme.wsattr(wtypes.text, mandatory=True)
|
macromodulation_name = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
modulation_period = wsme.wsattr(wtypes.text, mandatory=True)
|
modulation_period = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
|
|
||||||
macros = wsme.wsattr(
|
macros = wsme.wsattr(
|
||||||
wtypes.DictType(wtypes.text, int),
|
wtypes.DictType(wtypes.text, int),
|
||||||
|
@ -19,13 +19,17 @@ from surveil.api.datamodel import types
|
|||||||
|
|
||||||
|
|
||||||
class NotificationWay(types.Base):
|
class NotificationWay(types.Base):
|
||||||
notificationway_name = wsme.wsattr(wtypes.text, mandatory=True)
|
notificationway_name = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
host_notification_period = wsme.wsattr(wtypes.text, mandatory=True)
|
host_notification_period = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
service_notification_period = wsme.wsattr(wtypes.text, mandatory=True)
|
service_notification_period = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
host_notification_options = wsme.wsattr(wtypes.text, mandatory=True)
|
host_notification_options = wsme.wsattr(wtypes.ArrayType(wtypes.text),
|
||||||
service_notification_options = wsme.wsattr(wtypes.text, mandatory=True)
|
mandatory=False)
|
||||||
host_notification_commands = wsme.wsattr(wtypes.text, mandatory=True)
|
service_notification_options = wsme.wsattr(wtypes.ArrayType(wtypes.text),
|
||||||
service_notification_commands = wsme.wsattr(wtypes.text, mandatory=True)
|
mandatory=False)
|
||||||
|
host_notification_commands = wsme.wsattr(wtypes.ArrayType(wtypes.text),
|
||||||
|
mandatory=False)
|
||||||
|
service_notification_commands = wsme.wsattr(wtypes.ArrayType(wtypes.text),
|
||||||
|
mandatory=False)
|
||||||
min_business_impact = wsme.wsattr(int, mandatory=False)
|
min_business_impact = wsme.wsattr(int, mandatory=False)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -34,8 +38,8 @@ class NotificationWay(types.Base):
|
|||||||
notificationway_name="email_in_day",
|
notificationway_name="email_in_day",
|
||||||
host_notification_period="24x7",
|
host_notification_period="24x7",
|
||||||
service_notification_period="24x7",
|
service_notification_period="24x7",
|
||||||
host_notification_options="d,u,r,f,s",
|
host_notification_options=["d", "u", "r", "f", "s"],
|
||||||
service_notification_options="w,u,c,r,f",
|
service_notification_options=["w", "u", "c", "r", "f"],
|
||||||
service_notification_commands="notify-service",
|
service_notification_commands=["notify-service"],
|
||||||
host_notification_commands="notify-host"
|
host_notification_commands=["notify-host"]
|
||||||
)
|
)
|
||||||
|
@ -19,14 +19,15 @@ from surveil.api.datamodel import types
|
|||||||
|
|
||||||
|
|
||||||
class Realm(types.Base):
|
class Realm(types.Base):
|
||||||
realm_name = wsme.wsattr(wtypes.text, mandatory=True)
|
realm_name = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
realm_members = wsme.wsattr(wtypes.text, mandatory=True)
|
realm_members = wsme.wsattr(wtypes.ArrayType(wtypes.text),
|
||||||
default = wsme.wsattr(int, mandatory=True)
|
mandatory=False)
|
||||||
|
default = wsme.wsattr(int, mandatory=False)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def sample(cls):
|
def sample(cls):
|
||||||
return cls(
|
return cls(
|
||||||
realm_name='World',
|
realm_name='World',
|
||||||
realm_members='Europe,America,Asia',
|
realm_members=['Europe', 'America', 'Asia'],
|
||||||
default=0
|
default=0
|
||||||
)
|
)
|
||||||
|
@ -19,9 +19,10 @@ from surveil.api.datamodel import types
|
|||||||
|
|
||||||
|
|
||||||
class Service(types.Base):
|
class Service(types.Base):
|
||||||
host_name = wsme.wsattr(wtypes.text, mandatory=True)
|
host_name = wsme.wsattr(wtypes.ArrayType(wtypes.text),
|
||||||
|
mandatory=False)
|
||||||
|
|
||||||
service_description = wsme.wsattr(wtypes.text, mandatory=True)
|
service_description = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
|
|
||||||
check_command = wsme.wsattr(wtypes.text, mandatory=False)
|
check_command = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
|
|
||||||
@ -37,13 +38,16 @@ class Service(types.Base):
|
|||||||
|
|
||||||
notification_period = wsme.wsattr(wtypes.text, mandatory=False)
|
notification_period = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
|
|
||||||
contacts = wsme.wsattr(wtypes.text, mandatory=False)
|
contacts = wsme.wsattr(wtypes.ArrayType(wtypes.text),
|
||||||
|
mandatory=False)
|
||||||
|
|
||||||
contact_groups = wsme.wsattr(wtypes.text, mandatory=False)
|
contact_groups = wsme.wsattr(wtypes.ArrayType(wtypes.text),
|
||||||
|
mandatory=False)
|
||||||
|
|
||||||
passive_checks_enabled = wsme.wsattr(wtypes.text, mandatory=False)
|
passive_checks_enabled = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
|
|
||||||
use = wsme.wsattr(wtypes.text, mandatory=False)
|
use = wsme.wsattr(wtypes.ArrayType(wtypes.text),
|
||||||
|
mandatory=False)
|
||||||
|
|
||||||
name = wsme.wsattr(wtypes.text, mandatory=False)
|
name = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
|
|
||||||
@ -52,7 +56,7 @@ class Service(types.Base):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def sample(cls):
|
def sample(cls):
|
||||||
return cls(
|
return cls(
|
||||||
host_name="sample-server",
|
host_name=["sample-server"],
|
||||||
service_description="check-disk-sdb",
|
service_description="check-disk-sdb",
|
||||||
check_command="check-disk!/dev/sdb1",
|
check_command="check-disk!/dev/sdb1",
|
||||||
max_check_attempts=5,
|
max_check_attempts=5,
|
||||||
@ -61,7 +65,7 @@ class Service(types.Base):
|
|||||||
check_period="24x7",
|
check_period="24x7",
|
||||||
notification_interval=3,
|
notification_interval=3,
|
||||||
notification_period="24x7",
|
notification_period="24x7",
|
||||||
contacts="surveil-ptl,surveil-bob",
|
contacts=["surveil-ptl", "surveil-bob"],
|
||||||
contact_groups="linux-admins",
|
contact_groups=["linux-admins"],
|
||||||
passive_checks_enabled='1',
|
passive_checks_enabled='1',
|
||||||
)
|
)
|
||||||
|
@ -19,10 +19,12 @@ from surveil.api.datamodel import types
|
|||||||
|
|
||||||
|
|
||||||
class ServiceGroup(types.Base):
|
class ServiceGroup(types.Base):
|
||||||
servicegroup_name = wsme.wsattr(wtypes.text, mandatory=True)
|
servicegroup_name = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
members = wsme.wsattr(wtypes.text, mandatory=True)
|
members = wsme.wsattr(wtypes.ArrayType(wtypes.text),
|
||||||
|
mandatory=False)
|
||||||
alias = wsme.wsattr(wtypes.text, mandatory=False)
|
alias = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
servicegroup_members = wsme.wsattr(wtypes.text, mandatory=False)
|
servicegroup_members = wsme.wsattr(wtypes.ArrayType(wtypes.text),
|
||||||
|
mandatory=False)
|
||||||
notes = wsme.wsattr(wtypes.text, mandatory=False)
|
notes = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
notes_url = wsme.wsattr(wtypes.text, mandatory=False)
|
notes_url = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
action_url = wsme.wsattr(wtypes.text, mandatory=False)
|
action_url = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
@ -32,5 +34,10 @@ class ServiceGroup(types.Base):
|
|||||||
return cls(
|
return cls(
|
||||||
servicegroup_name='dbservices',
|
servicegroup_name='dbservices',
|
||||||
alias='Database Services',
|
alias='Database Services',
|
||||||
members='ms1,SQL Server,ms1,SQL Serverc Agent,ms1,SQL DTC'
|
members=['ms1',
|
||||||
|
'SQL Server',
|
||||||
|
'ms1',
|
||||||
|
'SQL Serverc Agent',
|
||||||
|
'ms1',
|
||||||
|
'SQL DTC']
|
||||||
)
|
)
|
||||||
|
@ -19,8 +19,10 @@ from surveil.api.datamodel import types
|
|||||||
|
|
||||||
|
|
||||||
class TimePeriod(types.Base):
|
class TimePeriod(types.Base):
|
||||||
timeperiod_name = wsme.wsattr(wtypes.text, mandatory=True)
|
timeperiod_name = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
exclude = wsme.wsattr(wtypes.text, mandatory=False)
|
exclude = wsme.wsattr(wtypes.ArrayType(wtypes.text),
|
||||||
|
mandatory=False)
|
||||||
|
alias = wsme.wsattr(wtypes.text, mandatory=False)
|
||||||
|
|
||||||
periods = wsme.wsattr(
|
periods = wsme.wsattr(
|
||||||
wtypes.DictType(wtypes.text, wtypes.text),
|
wtypes.DictType(wtypes.text, wtypes.text),
|
||||||
|
@ -22,10 +22,10 @@ class Contact(mongoengine.Document):
|
|||||||
service_notifications_enabled = mongoengine.StringField()
|
service_notifications_enabled = mongoengine.StringField()
|
||||||
host_notification_period = mongoengine.StringField()
|
host_notification_period = mongoengine.StringField()
|
||||||
service_notification_period = mongoengine.StringField()
|
service_notification_period = mongoengine.StringField()
|
||||||
host_notification_options = mongoengine.StringField()
|
host_notification_options = mongoengine.ListField()
|
||||||
service_notification_options = mongoengine.StringField()
|
service_notification_options = mongoengine.ListField()
|
||||||
host_notification_commands = mongoengine.StringField()
|
host_notification_commands = mongoengine.ListField()
|
||||||
service_notification_commands = mongoengine.StringField()
|
service_notification_commands = mongoengine.ListField()
|
||||||
email = mongoengine.StringField()
|
email = mongoengine.StringField()
|
||||||
pager = mongoengine.StringField()
|
pager = mongoengine.StringField()
|
||||||
can_submit_commands = mongoengine.StringField()
|
can_submit_commands = mongoengine.StringField()
|
||||||
|
@ -18,6 +18,6 @@ import mongoengine
|
|||||||
class ContactGroup(mongoengine.Document):
|
class ContactGroup(mongoengine.Document):
|
||||||
meta = {'collection': 'contactgroups'}
|
meta = {'collection': 'contactgroups'}
|
||||||
contactgroup_name = mongoengine.StringField()
|
contactgroup_name = mongoengine.StringField()
|
||||||
members = mongoengine.StringField()
|
members = mongoengine.ListField()
|
||||||
alias = mongoengine.StringField()
|
alias = mongoengine.StringField()
|
||||||
contactgroup_members = mongoengine.StringField()
|
contactgroup_members = mongoengine.ListField()
|
||||||
|
@ -20,16 +20,16 @@ class Host(mongoengine.Document):
|
|||||||
'collection': 'hosts',
|
'collection': 'hosts',
|
||||||
'strict': False
|
'strict': False
|
||||||
}
|
}
|
||||||
host_name = mongoengine.StringField()
|
name = mongoengine.StringField(unique=True, sparse=True)
|
||||||
|
host_name = mongoengine.StringField(unique=True, sparse=True)
|
||||||
address = mongoengine.StringField()
|
address = mongoengine.StringField()
|
||||||
max_check_attempts = mongoengine.IntField()
|
max_check_attempts = mongoengine.IntField()
|
||||||
check_period = mongoengine.StringField()
|
check_period = mongoengine.StringField()
|
||||||
contacts = mongoengine.StringField()
|
contacts = mongoengine.ListField()
|
||||||
contact_groups = mongoengine.StringField()
|
contact_groups = mongoengine.ListField()
|
||||||
notification_interval = mongoengine.IntField()
|
notification_interval = mongoengine.IntField()
|
||||||
notification_period = mongoengine.StringField()
|
notification_period = mongoengine.StringField()
|
||||||
use = mongoengine.StringField()
|
use = mongoengine.ListField()
|
||||||
name = mongoengine.StringField()
|
|
||||||
register = mongoengine.StringField()
|
register = mongoengine.StringField()
|
||||||
check_interval = mongoengine.IntField()
|
check_interval = mongoengine.IntField()
|
||||||
retry_interval = mongoengine.IntField()
|
retry_interval = mongoengine.IntField()
|
||||||
|
@ -17,10 +17,10 @@ import mongoengine
|
|||||||
|
|
||||||
class HostGroup(mongoengine.Document):
|
class HostGroup(mongoengine.Document):
|
||||||
meta = {'collection': 'hostgroups'}
|
meta = {'collection': 'hostgroups'}
|
||||||
hostgroup_name = mongoengine.StringField()
|
hostgroup_name = mongoengine.StringField(unique=True)
|
||||||
members = mongoengine.StringField()
|
members = mongoengine.ListField()
|
||||||
alias = mongoengine.StringField()
|
alias = mongoengine.StringField()
|
||||||
hostgroup_members = mongoengine.StringField()
|
hostgroup_members = mongoengine.ListField()
|
||||||
notes = mongoengine.StringField()
|
notes = mongoengine.StringField()
|
||||||
notes_url = mongoengine.StringField()
|
notes_url = mongoengine.StringField()
|
||||||
action_url = mongoengine.StringField()
|
action_url = mongoengine.StringField()
|
@ -20,8 +20,8 @@ class NotificationWays(mongoengine.Document):
|
|||||||
notificationway_name = mongoengine.StringField()
|
notificationway_name = mongoengine.StringField()
|
||||||
host_notification_period = mongoengine.StringField()
|
host_notification_period = mongoengine.StringField()
|
||||||
service_notification_period = mongoengine.StringField()
|
service_notification_period = mongoengine.StringField()
|
||||||
host_notification_options = mongoengine.StringField()
|
host_notification_options = mongoengine.ListField()
|
||||||
service_notification_options = mongoengine.StringField()
|
service_notification_options = mongoengine.ListField()
|
||||||
host_notification_commands = mongoengine.StringField()
|
host_notification_commands = mongoengine.ListField()
|
||||||
service_notification_commands = mongoengine.StringField()
|
service_notification_commands = mongoengine.ListField()
|
||||||
min_business_impact = mongoengine.IntField()
|
min_business_impact = mongoengine.IntField()
|
@ -17,6 +17,6 @@ import mongoengine
|
|||||||
|
|
||||||
class Realm(mongoengine.Document):
|
class Realm(mongoengine.Document):
|
||||||
meta = {'collection': 'realms'}
|
meta = {'collection': 'realms'}
|
||||||
realm_name = mongoengine.StringField()
|
realm_name = mongoengine.StringField(unique=True)
|
||||||
realm_members = mongoengine.StringField()
|
realm_members = mongoengine.ListField()
|
||||||
default = mongoengine.IntField()
|
default = mongoengine.IntField()
|
@ -20,9 +20,9 @@ class Service(mongoengine.Document):
|
|||||||
'collection': 'services',
|
'collection': 'services',
|
||||||
'strict': False
|
'strict': False
|
||||||
}
|
}
|
||||||
host_name = mongoengine.StringField()
|
host_name = mongoengine.ListField()
|
||||||
service_description = mongoengine.StringField()
|
service_description = mongoengine.StringField()
|
||||||
contacts = mongoengine.StringField()
|
contacts = mongoengine.ListField()
|
||||||
check_command = mongoengine.StringField()
|
check_command = mongoengine.StringField()
|
||||||
max_check_attempts = mongoengine.IntField()
|
max_check_attempts = mongoengine.IntField()
|
||||||
check_interval = mongoengine.IntField()
|
check_interval = mongoengine.IntField()
|
||||||
@ -30,8 +30,8 @@ class Service(mongoengine.Document):
|
|||||||
check_period = mongoengine.StringField()
|
check_period = mongoengine.StringField()
|
||||||
notification_interval = mongoengine.IntField()
|
notification_interval = mongoengine.IntField()
|
||||||
notification_period = mongoengine.StringField()
|
notification_period = mongoengine.StringField()
|
||||||
contact_groups = mongoengine.StringField()
|
contact_groups = mongoengine.ListField()
|
||||||
passive_checks_enabled = mongoengine.StringField()
|
passive_checks_enabled = mongoengine.StringField()
|
||||||
use = mongoengine.StringField()
|
use = mongoengine.ListField()
|
||||||
name = mongoengine.StringField()
|
name = mongoengine.StringField(unique=True, sparse=True)
|
||||||
register = mongoengine.StringField()
|
register = mongoengine.StringField()
|
@ -17,10 +17,10 @@ import mongoengine
|
|||||||
|
|
||||||
class ServiceGroup(mongoengine.Document):
|
class ServiceGroup(mongoengine.Document):
|
||||||
meta = {'collection': 'servicegroups'}
|
meta = {'collection': 'servicegroups'}
|
||||||
servicegroup_name = mongoengine.StringField()
|
servicegroup_name = mongoengine.StringField(unique=True)
|
||||||
members = mongoengine.StringField()
|
members = mongoengine.ListField()
|
||||||
alias = mongoengine.StringField()
|
alias = mongoengine.StringField()
|
||||||
servicegroup_members = mongoengine.StringField()
|
servicegroup_members = mongoengine.ListField()
|
||||||
notes = mongoengine.StringField()
|
notes = mongoengine.StringField()
|
||||||
notes_url = mongoengine.StringField()
|
notes_url = mongoengine.StringField()
|
||||||
action_url = mongoengine.StringField()
|
action_url = mongoengine.StringField()
|
@ -20,3 +20,4 @@ class TimePeriod(mongoengine.Document):
|
|||||||
timeperiod_name = mongoengine.StringField()
|
timeperiod_name = mongoengine.StringField()
|
||||||
exclude = mongoengine.StringField()
|
exclude = mongoengine.StringField()
|
||||||
periods = mongoengine.DictField()
|
periods = mongoengine.DictField()
|
||||||
|
alias = mongoengine.StringField()
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
"""Script to reinitialize surveil."""
|
"""Script to reinitialize surveil."""
|
||||||
|
|
||||||
import optparse
|
import optparse
|
||||||
import subprocess
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import influxdb
|
import influxdb
|
||||||
@ -23,6 +22,7 @@ import pymongo
|
|||||||
import surveilclient.client as sc
|
import surveilclient.client as sc
|
||||||
|
|
||||||
from surveil.api import config
|
from surveil.api import config
|
||||||
|
from surveil.cmd import pack_upload
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -49,6 +49,14 @@ def main():
|
|||||||
action='store_true')
|
action='store_true')
|
||||||
opts, _ = parser.parse_args(sys.argv)
|
opts, _ = parser.parse_args(sys.argv)
|
||||||
|
|
||||||
|
surveil_api_url = 'http://localhost:5311/v2'
|
||||||
|
surveil_auth_url = 'http://localhost:5311/v2/auth'
|
||||||
|
surveil_api_version = '2_0'
|
||||||
|
|
||||||
|
cli_surveil = sc.Client(surveil_api_url,
|
||||||
|
auth_url=surveil_auth_url,
|
||||||
|
version=surveil_api_version)
|
||||||
|
|
||||||
# Create a basic config in mongodb
|
# Create a basic config in mongodb
|
||||||
mongo = pymongo.MongoClient(config.surveil_api_config['mongodb_uri'])
|
mongo = pymongo.MongoClient(config.surveil_api_config['mongodb_uri'])
|
||||||
|
|
||||||
@ -71,73 +79,43 @@ def main():
|
|||||||
if opts.packs:
|
if opts.packs:
|
||||||
print ("Uploading packs...")
|
print ("Uploading packs...")
|
||||||
# Load the shinken packs
|
# Load the shinken packs
|
||||||
subprocess.call(
|
pack_upload.upload_pack(
|
||||||
[
|
|
||||||
"surveil-pack-upload",
|
|
||||||
"--mongo-uri=" + config.surveil_api_config['mongodb_uri'],
|
|
||||||
"/usr/share/monitoring/packs/sfl/openstack-keystone-http/",
|
"/usr/share/monitoring/packs/sfl/openstack-keystone-http/",
|
||||||
]
|
cli_surveil
|
||||||
)
|
)
|
||||||
|
|
||||||
subprocess.call(
|
pack_upload.upload_pack(
|
||||||
[
|
|
||||||
"surveil-pack-upload",
|
|
||||||
"--mongo-uri=" + config.surveil_api_config['mongodb_uri'],
|
|
||||||
"/usr/share/monitoring/packs/sfl/openstack-glance-http/",
|
"/usr/share/monitoring/packs/sfl/openstack-glance-http/",
|
||||||
]
|
cli_surveil
|
||||||
)
|
)
|
||||||
|
pack_upload.upload_pack(
|
||||||
subprocess.call(
|
|
||||||
[
|
|
||||||
"surveil-pack-upload",
|
|
||||||
"--mongo-uri=" + config.surveil_api_config['mongodb_uri'],
|
|
||||||
"/usr/share/monitoring/packs/sfl/generic-host/",
|
"/usr/share/monitoring/packs/sfl/generic-host/",
|
||||||
]
|
cli_surveil
|
||||||
)
|
)
|
||||||
|
pack_upload.upload_pack(
|
||||||
subprocess.call(
|
|
||||||
[
|
|
||||||
"surveil-pack-upload",
|
|
||||||
"--mongo-uri=" + config.surveil_api_config['mongodb_uri'],
|
|
||||||
"/usr/share/monitoring/packs/sfl/linux-system-nrpe/",
|
"/usr/share/monitoring/packs/sfl/linux-system-nrpe/",
|
||||||
]
|
cli_surveil
|
||||||
)
|
)
|
||||||
|
pack_upload.upload_pack(
|
||||||
subprocess.call(
|
|
||||||
[
|
|
||||||
"surveil-pack-upload",
|
|
||||||
"--mongo-uri=" + config.surveil_api_config['mongodb_uri'],
|
|
||||||
"/usr/share/monitoring/packs/sfl/openstack-nova-http/",
|
"/usr/share/monitoring/packs/sfl/openstack-nova-http/",
|
||||||
]
|
cli_surveil
|
||||||
)
|
)
|
||||||
|
pack_upload.upload_pack(
|
||||||
subprocess.call(
|
|
||||||
[
|
|
||||||
"surveil-pack-upload",
|
|
||||||
"--mongo-uri=" + config.surveil_api_config['mongodb_uri'],
|
|
||||||
"/usr/share/monitoring/packs/sfl/openstack-cinder-http/",
|
"/usr/share/monitoring/packs/sfl/openstack-cinder-http/",
|
||||||
]
|
cli_surveil
|
||||||
)
|
)
|
||||||
|
pack_upload.upload_pack(
|
||||||
subprocess.call(
|
|
||||||
[
|
|
||||||
"surveil-pack-upload",
|
|
||||||
"--mongo-uri=" + config.surveil_api_config['mongodb_uri'],
|
|
||||||
"/usr/share/monitoring/packs/sfl/openstack-host/",
|
"/usr/share/monitoring/packs/sfl/openstack-host/",
|
||||||
]
|
cli_surveil
|
||||||
)
|
)
|
||||||
|
|
||||||
cli_surveil = sc.Client('http://localhost:5311/v2',
|
|
||||||
auth_url='http://localhost:5311/v2/auth',
|
|
||||||
version='2_0')
|
|
||||||
|
|
||||||
# if --demo is specified, you get more hosts.
|
# if --demo is specified, you get more hosts.
|
||||||
if opts.demo is True:
|
if opts.demo is True:
|
||||||
print("Creating demo configuration...")
|
print("Creating demo configuration...")
|
||||||
# shinken's ws-arbiter
|
# shinken's ws-arbiter
|
||||||
cli_surveil.config.hosts.create(
|
cli_surveil.config.hosts.create(
|
||||||
use="generic-host",
|
use=["generic-host"],
|
||||||
contact_groups="admins",
|
contact_groups=["admins"],
|
||||||
host_name="ws-arbiter",
|
host_name="ws-arbiter",
|
||||||
address="localhost"
|
address="localhost"
|
||||||
)
|
)
|
||||||
@ -145,9 +123,9 @@ def main():
|
|||||||
check_command="check_tcp!7760",
|
check_command="check_tcp!7760",
|
||||||
check_interval="5",
|
check_interval="5",
|
||||||
check_period="24x7",
|
check_period="24x7",
|
||||||
contact_groups="admins",
|
contact_groups=["admins"],
|
||||||
contacts="admin",
|
contacts=["admin"],
|
||||||
host_name="ws-arbiter",
|
host_name=["ws-arbiter"],
|
||||||
max_check_attempts="5",
|
max_check_attempts="5",
|
||||||
notification_interval="30",
|
notification_interval="30",
|
||||||
notification_period="24x7",
|
notification_period="24x7",
|
||||||
@ -158,7 +136,7 @@ def main():
|
|||||||
# Linux-keystone template
|
# Linux-keystone template
|
||||||
cli_surveil.config.hosts.create(
|
cli_surveil.config.hosts.create(
|
||||||
host_name='test_keystone',
|
host_name='test_keystone',
|
||||||
use='openstack-keystone-http',
|
use=['openstack-keystone-http'],
|
||||||
address='127.0.0.1',
|
address='127.0.0.1',
|
||||||
custom_fields={
|
custom_fields={
|
||||||
"_OS_AUTH_URL": "bla",
|
"_OS_AUTH_URL": "bla",
|
||||||
@ -173,7 +151,7 @@ def main():
|
|||||||
# openstack-host template
|
# openstack-host template
|
||||||
cli_surveil.config.hosts.create(
|
cli_surveil.config.hosts.create(
|
||||||
host_name='openstackceilometer-host',
|
host_name='openstackceilometer-host',
|
||||||
use='openstack-host',
|
use=['openstack-host'],
|
||||||
address='127.0.0.1',
|
address='127.0.0.1',
|
||||||
custom_fields={
|
custom_fields={
|
||||||
"_OS_AUTH_URL": "bla",
|
"_OS_AUTH_URL": "bla",
|
||||||
@ -188,7 +166,7 @@ def main():
|
|||||||
# DOWN HOST (cant resolve)
|
# DOWN HOST (cant resolve)
|
||||||
cli_surveil.config.hosts.create(
|
cli_surveil.config.hosts.create(
|
||||||
host_name='srv-apache-01',
|
host_name='srv-apache-01',
|
||||||
use='linux-system-nrpe',
|
use=['linux-system-nrpe'],
|
||||||
address='srv-apache-01',
|
address='srv-apache-01',
|
||||||
custom_fields={
|
custom_fields={
|
||||||
"_TRAFFICLIMIT": "100000",
|
"_TRAFFICLIMIT": "100000",
|
||||||
@ -199,7 +177,7 @@ def main():
|
|||||||
cli_surveil.config.hosts.create(
|
cli_surveil.config.hosts.create(
|
||||||
host_name='myparentisdown',
|
host_name='myparentisdown',
|
||||||
address='dfgsdgsdgf',
|
address='dfgsdgsdgf',
|
||||||
parents='srv-apache-01',
|
parents=['srv-apache-01'],
|
||||||
)
|
)
|
||||||
|
|
||||||
# UP host, no template
|
# UP host, no template
|
||||||
@ -211,7 +189,7 @@ def main():
|
|||||||
# NRPE host, UP
|
# NRPE host, UP
|
||||||
cli_surveil.config.hosts.create(
|
cli_surveil.config.hosts.create(
|
||||||
host_name='srv-monitoring-01',
|
host_name='srv-monitoring-01',
|
||||||
use='linux-system-nrpe',
|
use=['linux-system-nrpe'],
|
||||||
address='127.0.0.1',
|
address='127.0.0.1',
|
||||||
custom_fields={
|
custom_fields={
|
||||||
"_TRAFFICLIMIT": "500000",
|
"_TRAFFICLIMIT": "500000",
|
||||||
@ -221,8 +199,8 @@ def main():
|
|||||||
# Has parent, UP
|
# Has parent, UP
|
||||||
cli_surveil.config.hosts.create(
|
cli_surveil.config.hosts.create(
|
||||||
host_name='sw-iwebcore-01',
|
host_name='sw-iwebcore-01',
|
||||||
parents='srv-monitoring-01',
|
parents=['srv-monitoring-01'],
|
||||||
use='generic-host',
|
use=['generic-host'],
|
||||||
address='127.0.0.1',
|
address='127.0.0.1',
|
||||||
custom_fields={
|
custom_fields={
|
||||||
"_TRAFFICLIMIT": "200000",
|
"_TRAFFICLIMIT": "200000",
|
||||||
@ -232,8 +210,8 @@ def main():
|
|||||||
# Has chain of 2 parents, UP
|
# Has chain of 2 parents, UP
|
||||||
cli_surveil.config.hosts.create(
|
cli_surveil.config.hosts.create(
|
||||||
host_name='srv-ldap-01',
|
host_name='srv-ldap-01',
|
||||||
parents='sw-iwebcore-01',
|
parents=['sw-iwebcore-01'],
|
||||||
use='generic-host',
|
use=['generic-host'],
|
||||||
address='127.0.0.1',
|
address='127.0.0.1',
|
||||||
custom_fields={
|
custom_fields={
|
||||||
"_TRAFFICLIMIT": "5000000",
|
"_TRAFFICLIMIT": "5000000",
|
||||||
@ -242,8 +220,8 @@ def main():
|
|||||||
|
|
||||||
# UP host with down service
|
# UP host with down service
|
||||||
cli_surveil.config.hosts.create(
|
cli_surveil.config.hosts.create(
|
||||||
use="generic-host",
|
use=["generic-host"],
|
||||||
contact_groups="admins",
|
contact_groups=["admins"],
|
||||||
host_name="myserviceisdown",
|
host_name="myserviceisdown",
|
||||||
address="localhost"
|
address="localhost"
|
||||||
)
|
)
|
||||||
@ -251,9 +229,9 @@ def main():
|
|||||||
check_command="check_tcp!4553",
|
check_command="check_tcp!4553",
|
||||||
check_interval="5",
|
check_interval="5",
|
||||||
check_period="24x7",
|
check_period="24x7",
|
||||||
contact_groups="admins",
|
contact_groups=["admins"],
|
||||||
contacts="admin",
|
contacts=["admin"],
|
||||||
host_name="myserviceisdown",
|
host_name=["myserviceisdown"],
|
||||||
max_check_attempts="5",
|
max_check_attempts="5",
|
||||||
notification_interval="30",
|
notification_interval="30",
|
||||||
notification_period="24x7",
|
notification_period="24x7",
|
||||||
|
@ -1,27 +1,25 @@
|
|||||||
# Copyright 2014 - Savoir-Faire Linux inc.
|
# Copyright 2014 - Savoir-Faire Linux inc.
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# it under the terms of the GNU Affero General Public License as
|
# not use this file except in compliance with the License. You may obtain
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
# a copy of the License at
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
# 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
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
# along with this program. If not, see `<http://www.gnu.org/licenses/>`.
|
# 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.
|
||||||
|
|
||||||
"""Script to push a Shinken pack to Surveil"""
|
"""Script to push a Shinken pack to Surveil"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import fnmatch
|
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pymongo import mongo_client
|
import surveilclient.client as sc
|
||||||
from alignak.objects import config
|
|
||||||
|
from surveil.cmd import surveil_from_nagios
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -30,56 +28,37 @@ def main():
|
|||||||
prog='surveil-pack-upload',
|
prog='surveil-pack-upload',
|
||||||
add_help=False,
|
add_help=False,
|
||||||
)
|
)
|
||||||
parser.add_argument('--mongo-uri',
|
parser.add_argument('--surveil_api_url',
|
||||||
default='mongodb://localhost:27017',
|
default='http://localhost:5311/v2',
|
||||||
help='Defaults to localhost', type=str)
|
type=str)
|
||||||
parser.add_argument('pack', metavar='[Pack]', type=str, nargs=1,
|
parser.add_argument('--surveil_auth_url',
|
||||||
|
default='http://localhost:5311/v2/auth',
|
||||||
|
type=str)
|
||||||
|
parser.add_argument('--surveil_api_version',
|
||||||
|
default='2_0',
|
||||||
|
type=str)
|
||||||
|
parser.add_argument('pack',
|
||||||
|
metavar='[Pack]',
|
||||||
|
type=str,
|
||||||
|
nargs=1,
|
||||||
help='Pack directory')
|
help='Pack directory')
|
||||||
|
|
||||||
(options, args) = parser.parse_known_args(sys.argv[1:])
|
(options, args) = parser.parse_known_args(sys.argv[1:])
|
||||||
|
|
||||||
pack_dir = options.pack[0]
|
cli_surveil = sc.Client(options.surveil_api_url,
|
||||||
pack_name = os.path.basename(os.path.normpath(pack_dir))
|
auth_url=options.surveil_auth_url,
|
||||||
|
version=options.surveil_api_version)
|
||||||
|
|
||||||
# Find the .cfg files
|
upload_pack(options.pack[0], cli_surveil)
|
||||||
cfg_files = [
|
|
||||||
os.path.join(dirpath, f)
|
|
||||||
for dirpath, dirnames, files in os.walk(pack_dir)
|
|
||||||
for f in fnmatch.filter(files, '*.cfg')
|
|
||||||
]
|
|
||||||
|
|
||||||
# Load the config
|
|
||||||
conf = config.Config()
|
|
||||||
loaded_conf = conf.read_config(cfg_files)
|
|
||||||
raw_objects = conf.read_config_buf(loaded_conf)
|
|
||||||
|
|
||||||
# Remove the empty items
|
def upload_pack(pack_dir, client):
|
||||||
non_empty_config = {k: v for k, v in raw_objects.items() if v}
|
# pack_name = os.path.basename(os.path.normpath(pack_dir))
|
||||||
|
|
||||||
for config_type in non_empty_config:
|
surveil_config = surveil_from_nagios.load_config(pack_dir)
|
||||||
for config_item in non_empty_config[config_type]:
|
|
||||||
# Tag the config objects
|
|
||||||
config_item['SURVEIL_PACK_NAME'] = pack_name
|
|
||||||
|
|
||||||
# Replace lists with csv
|
config_manager = client.config
|
||||||
items_to_modify = (
|
for object_type, objects in surveil_config.items():
|
||||||
[i for i in config_item.items() if isinstance(i[1], list)]
|
object_manager = getattr(config_manager, object_type)
|
||||||
)
|
for object in objects:
|
||||||
for i in items_to_modify:
|
object_manager.create(**object)
|
||||||
config_item[i[0]] = ','.join(i[1])
|
|
||||||
|
|
||||||
# Remove the existing pack from mongodb
|
|
||||||
mongo = mongo_client.MongoClient(options.mongo_uri)
|
|
||||||
mongo_shinken = mongo.shinken
|
|
||||||
for collection in (
|
|
||||||
[c for c
|
|
||||||
in mongo_shinken.collection_names()
|
|
||||||
if not c.startswith("system.")]
|
|
||||||
):
|
|
||||||
mongo_shinken[collection].remove({'SURVEIL_PACK_NAME': pack_name})
|
|
||||||
|
|
||||||
# Add the replacement pack
|
|
||||||
for config_type in non_empty_config:
|
|
||||||
mongo_shinken[config_type + 's'].insert(
|
|
||||||
non_empty_config[config_type]
|
|
||||||
)
|
|
||||||
|
226
surveil/cmd/surveil_from_nagios.py
Normal file
226
surveil/cmd/surveil_from_nagios.py
Normal file
@ -0,0 +1,226 @@
|
|||||||
|
# Copyright 2014 - Savoir-Faire Linux inc.
|
||||||
|
#
|
||||||
|
# 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 __future__ import print_function
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import fnmatch
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import six
|
||||||
|
import wsme
|
||||||
|
|
||||||
|
from surveil.api.datamodel.config import businessimpactmodulation
|
||||||
|
from surveil.api.datamodel.config import checkmodulation
|
||||||
|
from surveil.api.datamodel.config import command
|
||||||
|
from surveil.api.datamodel.config import contact
|
||||||
|
from surveil.api.datamodel.config import contactgroup
|
||||||
|
from surveil.api.datamodel.config import host
|
||||||
|
from surveil.api.datamodel.config import hostgroup
|
||||||
|
from surveil.api.datamodel.config import macromodulation
|
||||||
|
from surveil.api.datamodel.config import notificationway
|
||||||
|
from surveil.api.datamodel.config import realm
|
||||||
|
from surveil.api.datamodel.config import service
|
||||||
|
from surveil.api.datamodel.config import servicegroup
|
||||||
|
from surveil.api.datamodel.config import timeperiod
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# Parse the arguments
|
||||||
|
parser = argparse.ArgumentParser(add_help=False)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'path',
|
||||||
|
metavar='[path]',
|
||||||
|
type=str,
|
||||||
|
nargs=1,
|
||||||
|
help='Configuration path'
|
||||||
|
)
|
||||||
|
|
||||||
|
(options, args) = parser.parse_known_args(sys.argv[1:])
|
||||||
|
|
||||||
|
pack_dir = options.path[0]
|
||||||
|
|
||||||
|
surveil_config = load_config(pack_dir)
|
||||||
|
|
||||||
|
print(json.dumps(surveil_config, indent=4, sort_keys=True))
|
||||||
|
|
||||||
|
|
||||||
|
def load_config(path):
|
||||||
|
"""From a directory, returns Surveil configuration"""
|
||||||
|
|
||||||
|
if os.path.isdir(path):
|
||||||
|
# Find the .cfg files
|
||||||
|
cfg_files = [
|
||||||
|
os.path.join(dirpath, f)
|
||||||
|
for dirpath, dirnames, files in os.walk(path)
|
||||||
|
for f in fnmatch.filter(files, '*.cfg')
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
cfg_files = [path]
|
||||||
|
|
||||||
|
nagios_config = {}
|
||||||
|
|
||||||
|
for cfg_file in cfg_files:
|
||||||
|
# Open the file
|
||||||
|
f = open(cfg_file, 'r')
|
||||||
|
config_string = f.read()
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
# Load the config
|
||||||
|
file_config = _load_nagios_config(config_string)
|
||||||
|
|
||||||
|
# Append to the loaded config
|
||||||
|
for object_type, objects in file_config.items():
|
||||||
|
nagios_config[object_type] = nagios_config.get(
|
||||||
|
object_type,
|
||||||
|
[]
|
||||||
|
) + objects
|
||||||
|
|
||||||
|
surveil_config = _transform_config(nagios_config)
|
||||||
|
|
||||||
|
return surveil_config
|
||||||
|
|
||||||
|
|
||||||
|
def _load_nagios_config(config_string):
|
||||||
|
"""Given a nagios configuration string, returns a python dict"""
|
||||||
|
config = {}
|
||||||
|
|
||||||
|
# Find all config objects
|
||||||
|
config_objects = re.finditer(
|
||||||
|
r'define\s(?P<object_type>\w*)\s*{(?P<object_properties>[^{}]*)}',
|
||||||
|
config_string
|
||||||
|
)
|
||||||
|
|
||||||
|
# For each object in the file...
|
||||||
|
for object_match in config_objects:
|
||||||
|
object_type = object_match.group("object_type")
|
||||||
|
|
||||||
|
config_object = {}
|
||||||
|
|
||||||
|
# For each property of the object...
|
||||||
|
for property_match in re.finditer(
|
||||||
|
r'(?P<property>[^\s]+)\s*(?P<value>.*?)\s*\n',
|
||||||
|
object_match.group("object_properties")
|
||||||
|
):
|
||||||
|
|
||||||
|
config_object[
|
||||||
|
property_match.group('property')
|
||||||
|
] = property_match.group('value')
|
||||||
|
|
||||||
|
# Append the config object
|
||||||
|
config[object_type + 's'] = config.get(
|
||||||
|
object_type + 's', []
|
||||||
|
) + [config_object]
|
||||||
|
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
def _transform_config(nagios_config):
|
||||||
|
"""Given a nagios config dict, returns surveil configuration"""
|
||||||
|
transformed_config = {}
|
||||||
|
|
||||||
|
for object_type, objects in nagios_config.items():
|
||||||
|
for config_object in objects:
|
||||||
|
|
||||||
|
# PROPERTY NAMES TRANSFORMATIONS
|
||||||
|
name_transformed_obj = _transform_property_names(
|
||||||
|
config_object,
|
||||||
|
object_type
|
||||||
|
)
|
||||||
|
|
||||||
|
# PROPERTY TYPES TRANSORMATIONS
|
||||||
|
type_transformed_obj = _transform_property_types(
|
||||||
|
name_transformed_obj,
|
||||||
|
object_type
|
||||||
|
)
|
||||||
|
|
||||||
|
transformed_config[object_type] = transformed_config.get(
|
||||||
|
object_type,
|
||||||
|
[]
|
||||||
|
) + [type_transformed_obj]
|
||||||
|
|
||||||
|
return transformed_config
|
||||||
|
|
||||||
|
|
||||||
|
def _transform_property_types(config_object, object_type):
|
||||||
|
transformed_object = {}
|
||||||
|
|
||||||
|
datamodels = {
|
||||||
|
"businessimpactmodulations": businessimpactmodulation.BusinessImpactModulation,
|
||||||
|
"checkmodulations": checkmodulation.CheckModulation,
|
||||||
|
"commands": command.Command,
|
||||||
|
"contacts": contact.Contact,
|
||||||
|
"contactgroups": contactgroup.ContactGroup,
|
||||||
|
"hosts": host.Host,
|
||||||
|
"hostgroups": hostgroup.HostGroup,
|
||||||
|
"macromodulations": macromodulation.MacroModulation,
|
||||||
|
"notificationways": notificationway.NotificationWay,
|
||||||
|
"realms": realm.Realm,
|
||||||
|
"services": service.Service,
|
||||||
|
"servicegroups": servicegroup.ServiceGroup,
|
||||||
|
"timeperiods": timeperiod.TimePeriod,
|
||||||
|
}
|
||||||
|
object_datamodel = datamodels[object_type]
|
||||||
|
object_wsmeattrs = object_datamodel._wsme_attributes
|
||||||
|
for attribute in object_wsmeattrs:
|
||||||
|
|
||||||
|
if attribute.name in config_object:
|
||||||
|
# COMMA-SEPARATED => List
|
||||||
|
if isinstance(attribute._get_datatype(), wsme.types.ArrayType):
|
||||||
|
transformed_object[attribute.name] = config_object[attribute.name].split(',')
|
||||||
|
# Integers
|
||||||
|
elif attribute._get_datatype() in six.integer_types:
|
||||||
|
transformed_object[attribute.name] = int(config_object[attribute.name])
|
||||||
|
# Strings
|
||||||
|
else:
|
||||||
|
transformed_object[attribute.name] = config_object[attribute.name]
|
||||||
|
|
||||||
|
return transformed_object
|
||||||
|
|
||||||
|
|
||||||
|
def _transform_property_names(config_object, object_type):
|
||||||
|
transformed_object = {}
|
||||||
|
|
||||||
|
# HOSTS
|
||||||
|
if object_type in ['hosts', 'services']:
|
||||||
|
transformed_object['custom_fields'] = {}
|
||||||
|
for property, value in config_object.items():
|
||||||
|
if property.startswith('_'):
|
||||||
|
transformed_object['custom_fields'][property] = value
|
||||||
|
else:
|
||||||
|
transformed_object[property] = value
|
||||||
|
# TIMEPERIODS
|
||||||
|
elif object_type == 'timeperiods':
|
||||||
|
transformed_object['periods'] = {}
|
||||||
|
properties = [p.name for p in timeperiod.TimePeriod._wsme_attributes]
|
||||||
|
for property, value in config_object.items():
|
||||||
|
if property not in properties:
|
||||||
|
transformed_object['periods'][property] = value
|
||||||
|
else:
|
||||||
|
transformed_object[property] = value
|
||||||
|
# OTHER OBJECTS
|
||||||
|
else:
|
||||||
|
for property, value in config_object.items():
|
||||||
|
transformed_object[property] = value
|
||||||
|
return transformed_object
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
||||||
|
|
@ -27,11 +27,13 @@ class TestContactGroupsController(functionalTest.FunctionalTest):
|
|||||||
self.groups = [
|
self.groups = [
|
||||||
{
|
{
|
||||||
'contactgroup_name': 'novell-admins',
|
'contactgroup_name': 'novell-admins',
|
||||||
'members': 'jdoe,rtobert,tzach',
|
'members': ["jdoe", "rtobert", "tzach"],
|
||||||
|
'contactgroup_members': []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'contactgroup_name': 'linux-adminx',
|
'contactgroup_name': 'linux-adminx',
|
||||||
'members': 'linus,richard',
|
'members': ['linus', 'richard'],
|
||||||
|
'contactgroup_members': []
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
self.mongoconnection.shinken.contactgroups.insert(
|
self.mongoconnection.shinken.contactgroups.insert(
|
||||||
@ -58,7 +60,7 @@ class TestContactGroupsController(functionalTest.FunctionalTest):
|
|||||||
def test_create_contactgroup(self):
|
def test_create_contactgroup(self):
|
||||||
g = contactgroup.ContactGroup(
|
g = contactgroup.ContactGroup(
|
||||||
contactgroup_name='John',
|
contactgroup_name='John',
|
||||||
members="marie,bob,joe",
|
members=["marie", "bob", "joe"],
|
||||||
)
|
)
|
||||||
|
|
||||||
self.post_json('/v2/config/contactgroups', g.as_dict())
|
self.post_json('/v2/config/contactgroups', g.as_dict())
|
||||||
@ -83,18 +85,18 @@ class TestContactGroupsController(functionalTest.FunctionalTest):
|
|||||||
self.mongoconnection.shinken.contactgroups.find_one(
|
self.mongoconnection.shinken.contactgroups.find_one(
|
||||||
{'contactgroup_name': 'novell-admins'}
|
{'contactgroup_name': 'novell-admins'}
|
||||||
)['members'],
|
)['members'],
|
||||||
'jdoe,rtobert,tzach'
|
['jdoe', 'rtobert', 'tzach']
|
||||||
)
|
)
|
||||||
|
|
||||||
self.put_json(
|
self.put_json(
|
||||||
'/v2/config/contactgroups/novell-admins',
|
'/v2/config/contactgroups/novell-admins',
|
||||||
{"contactgroup_name": "novell-admins",
|
{"contactgroup_name": "novell-admins",
|
||||||
"members": "updated"}
|
"members": ["updated"]}
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.mongoconnection.shinken.contactgroups.find_one(
|
self.mongoconnection.shinken.contactgroups.find_one(
|
||||||
{'contactgroup_name': 'novell-admins'}
|
{'contactgroup_name': 'novell-admins'}
|
||||||
)['members'],
|
)['members'],
|
||||||
'updated'
|
['updated']
|
||||||
)
|
)
|
||||||
|
@ -27,11 +27,19 @@ class TestContactsController(functionalTest.FunctionalTest):
|
|||||||
self.contacts = [
|
self.contacts = [
|
||||||
{
|
{
|
||||||
'contact_name': 'bobby',
|
'contact_name': 'bobby',
|
||||||
'email': 'bob@bob.com'
|
'email': 'bob@bob.com',
|
||||||
|
'service_notification_options': [],
|
||||||
|
'service_notification_commands': [],
|
||||||
|
'host_notification_options': [],
|
||||||
|
'host_notification_commands': []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'contact_name': 'marie',
|
'contact_name': 'marie',
|
||||||
'email': 'marie@marie.com'
|
'email': 'marie@marie.com',
|
||||||
|
'service_notification_options': [],
|
||||||
|
'service_notification_commands': [],
|
||||||
|
'host_notification_options': [],
|
||||||
|
'host_notification_commands': []
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
self.mongoconnection.shinken.contacts.insert(
|
self.mongoconnection.shinken.contacts.insert(
|
||||||
|
@ -27,11 +27,13 @@ class TestHostGroupsController(functionalTest.FunctionalTest):
|
|||||||
self.groups = [
|
self.groups = [
|
||||||
{
|
{
|
||||||
'hostgroup_name': 'novell-servers',
|
'hostgroup_name': 'novell-servers',
|
||||||
'members': 'netware1,netware2,netware3,netware4',
|
'members': ['netware1', 'netware2', 'netware3', 'netware4'],
|
||||||
|
'hostgroup_members': []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'hostgroup_name': 'otherservers',
|
'hostgroup_name': 'otherservers',
|
||||||
'members': 'googul,sfl',
|
'members': ['googul', 'sfl'],
|
||||||
|
'hostgroup_members': []
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
self.mongoconnection.shinken.hostgroups.insert(
|
self.mongoconnection.shinken.hostgroups.insert(
|
||||||
@ -58,7 +60,7 @@ class TestHostGroupsController(functionalTest.FunctionalTest):
|
|||||||
def test_create_hostgroup(self):
|
def test_create_hostgroup(self):
|
||||||
s = hostgroup.HostGroup(
|
s = hostgroup.HostGroup(
|
||||||
hostgroup_name='John',
|
hostgroup_name='John',
|
||||||
members="marie,bob,joe",
|
members=['marie', 'bob', 'joe'],
|
||||||
)
|
)
|
||||||
|
|
||||||
self.post_json('/v2/config/hostgroups', s.as_dict())
|
self.post_json('/v2/config/hostgroups', s.as_dict())
|
||||||
@ -83,18 +85,18 @@ class TestHostGroupsController(functionalTest.FunctionalTest):
|
|||||||
self.mongoconnection.shinken.hostgroups.find_one(
|
self.mongoconnection.shinken.hostgroups.find_one(
|
||||||
{'hostgroup_name': 'novell-servers'}
|
{'hostgroup_name': 'novell-servers'}
|
||||||
)['members'],
|
)['members'],
|
||||||
'netware1,netware2,netware3,netware4'
|
['netware1', 'netware2', 'netware3', 'netware4']
|
||||||
)
|
)
|
||||||
|
|
||||||
self.put_json(
|
self.put_json(
|
||||||
'/v2/config/hostgroups/novell-servers',
|
'/v2/config/hostgroups/novell-servers',
|
||||||
{"hostgroup_name": "novell-servers",
|
{"hostgroup_name": "novell-servers",
|
||||||
"members": "updated"}
|
"members": ["updated"]}
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.mongoconnection.shinken.hostgroups.find_one(
|
self.mongoconnection.shinken.hostgroups.find_one(
|
||||||
{'hostgroup_name': 'novell-servers'}
|
{'hostgroup_name': 'novell-servers'}
|
||||||
)['members'],
|
)['members'],
|
||||||
'updated'
|
['updated']
|
||||||
)
|
)
|
||||||
|
@ -26,25 +26,41 @@ class TestHostController(functionalTest.FunctionalTest):
|
|||||||
super(TestHostController, self).setUp()
|
super(TestHostController, self).setUp()
|
||||||
self.hosts = [
|
self.hosts = [
|
||||||
{
|
{
|
||||||
"host_name": "bogus-router", "address": "192.168.1.254",
|
"host_name": "bogus-router",
|
||||||
"max_check_attempts": 5, "check_period": "24x7",
|
"address": "192.168.1.254",
|
||||||
"contacts": "admin,carl", "contact_groups": "router-admins",
|
"max_check_attempts": 5,
|
||||||
"notification_interval": 30, "notification_period": "24x7",
|
"check_period": "24x7",
|
||||||
"custom_fields": {}
|
"contacts": ["admin", "carl"],
|
||||||
|
"contact_groups": ["router-admins"],
|
||||||
|
"notification_interval": 30,
|
||||||
|
"notification_period": "24x7",
|
||||||
|
"custom_fields": {},
|
||||||
|
"use": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"host_name": "bogus-router2", "address": "192.168.1.254",
|
"host_name": "bogus-router2",
|
||||||
"max_check_attempts": 5, "check_period": "24x7",
|
"address": "192.168.1.254",
|
||||||
"contacts": "admin,carl", "contact_groups": "router-admins",
|
"max_check_attempts": 5,
|
||||||
"notification_interval": 30, "notification_period": "24x7",
|
"check_period": "24x7",
|
||||||
"custom_fields": {}
|
"contacts": ["admin", "carl"],
|
||||||
|
"contact_groups": ["router-admins"],
|
||||||
|
"notification_interval": 30,
|
||||||
|
"notification_period": "24x7",
|
||||||
|
"custom_fields": {},
|
||||||
|
"use": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"host_name": "bogus-router333", "address": "192.168.1.254",
|
"host_name": "bogus-router333",
|
||||||
"max_check_attempts": 5, "check_period": "24x7",
|
"address": "192.168.1.254",
|
||||||
"contacts": "admin,carl", "contact_groups": "router-admins",
|
"max_check_attempts": 5,
|
||||||
"notification_interval": 30, "notification_period": "24x7",
|
"check_period": "24x7",
|
||||||
'use': 'test', "custom_fields": {}
|
"contacts": ["admin", "carl"],
|
||||||
|
"contact_groups": ["router-admins"],
|
||||||
|
"notification_interval": 30,
|
||||||
|
"notification_period": "24x7",
|
||||||
|
'use': ['test'],
|
||||||
|
"custom_fields": {},
|
||||||
|
"use": []
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
self.mongoconnection.shinken.hosts.insert(
|
self.mongoconnection.shinken.hosts.insert(
|
||||||
@ -53,7 +69,7 @@ class TestHostController(functionalTest.FunctionalTest):
|
|||||||
|
|
||||||
self.services = [
|
self.services = [
|
||||||
{
|
{
|
||||||
"host_name": "bogus-router",
|
"host_name": ["bogus-router"],
|
||||||
"service_description": "service-example",
|
"service_description": "service-example",
|
||||||
"check_command": "check-disk!/dev/sdb1",
|
"check_command": "check-disk!/dev/sdb1",
|
||||||
"max_check_attempts": 5,
|
"max_check_attempts": 5,
|
||||||
@ -62,8 +78,9 @@ class TestHostController(functionalTest.FunctionalTest):
|
|||||||
"check_period": "24x7",
|
"check_period": "24x7",
|
||||||
"notification_interval": 30,
|
"notification_interval": 30,
|
||||||
"notification_period": "24x7",
|
"notification_period": "24x7",
|
||||||
"contacts": "surveil-ptl,surveil-bob",
|
"contacts": ["surveil-ptl", "surveil-bob"],
|
||||||
"contact_groups": "linux-admins"
|
"contact_groups": ["linux-admins"],
|
||||||
|
"use": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
self.mongoconnection.shinken.services.insert(
|
self.mongoconnection.shinken.services.insert(
|
||||||
@ -82,11 +99,17 @@ class TestHostController(functionalTest.FunctionalTest):
|
|||||||
def test_get_all_hosts_templates(self):
|
def test_get_all_hosts_templates(self):
|
||||||
self.mongoconnection.shinken.hosts.insert(
|
self.mongoconnection.shinken.hosts.insert(
|
||||||
copy.deepcopy(
|
copy.deepcopy(
|
||||||
{"host_name": "bogus-router345345", "address": "192.168.1.254",
|
{"host_name": "bogus-router345345",
|
||||||
"max_check_attempts": 5, "check_period": "24x7",
|
"address": "192.168.1.254",
|
||||||
"contacts": "admin,carl", "contact_groups": "router-admins",
|
"max_check_attempts": 5,
|
||||||
"notification_interval": 30, "notification_period": "24x7",
|
"check_period": "24x7",
|
||||||
"register": "0", "custom_fields": {}}
|
"contacts": ["admin", "carl"],
|
||||||
|
"contact_groups": ["router-admins"],
|
||||||
|
"notification_interval": 30,
|
||||||
|
"notification_period": "24x7",
|
||||||
|
"register": "0",
|
||||||
|
"custom_fields": {},
|
||||||
|
"use": []}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
response = self.get('/v2/config/hosts')
|
response = self.get('/v2/config/hosts')
|
||||||
@ -116,7 +139,7 @@ class TestHostController(functionalTest.FunctionalTest):
|
|||||||
def test_update_host(self):
|
def test_update_host(self):
|
||||||
put_host = {
|
put_host = {
|
||||||
u'host_name': u'bogus-router333',
|
u'host_name': u'bogus-router333',
|
||||||
u'contacts': u'newcontacts',
|
u'contacts': [u'newcontacts'],
|
||||||
}
|
}
|
||||||
response = self.put_json(
|
response = self.put_json(
|
||||||
"/v2/config/hosts/bogus-router333", params=put_host
|
"/v2/config/hosts/bogus-router333", params=put_host
|
||||||
@ -132,12 +155,12 @@ class TestHostController(functionalTest.FunctionalTest):
|
|||||||
'address': u'192.168.1.254',
|
'address': u'192.168.1.254',
|
||||||
'check_period': u'24x7',
|
'check_period': u'24x7',
|
||||||
'notification_interval': 30,
|
'notification_interval': 30,
|
||||||
'contacts': u'newcontacts',
|
'contacts': [u'newcontacts'],
|
||||||
'notification_period': u'24x7',
|
'notification_period': u'24x7',
|
||||||
'contact_groups': u'router-admins',
|
'contact_groups': [u'router-admins'],
|
||||||
'host_name': u'bogus-router333',
|
'host_name': u'bogus-router333',
|
||||||
'max_check_attempts': 5,
|
'max_check_attempts': 5,
|
||||||
'use': u'test',
|
'use': [],
|
||||||
'custom_fields': {},
|
'custom_fields': {},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,11 +182,12 @@ class TestHostController(functionalTest.FunctionalTest):
|
|||||||
"address": "192.168.1.254",
|
"address": "192.168.1.254",
|
||||||
"max_check_attempts": 5,
|
"max_check_attempts": 5,
|
||||||
"check_period": "24x7",
|
"check_period": "24x7",
|
||||||
"contacts": "admin,carl",
|
"contacts": ["admin", "carl"],
|
||||||
"contact_groups": "router-admins",
|
"contact_groups": ["router-admins"],
|
||||||
"notification_interval": 3,
|
"notification_interval": 3,
|
||||||
"notification_period": "24x7",
|
"notification_period": "24x7",
|
||||||
"custom_fields": {}
|
"custom_fields": {},
|
||||||
|
"use": []
|
||||||
}
|
}
|
||||||
response = self.post_json("/v2/config/hosts", params=new_host)
|
response = self.post_json("/v2/config/hosts", params=new_host)
|
||||||
|
|
||||||
|
@ -28,19 +28,19 @@ class TestNotificationWayController(functionalTest.FunctionalTest):
|
|||||||
'notificationway_name': 'email_in_day',
|
'notificationway_name': 'email_in_day',
|
||||||
'host_notification_period': '24x7',
|
'host_notification_period': '24x7',
|
||||||
'service_notification_period': '24x7',
|
'service_notification_period': '24x7',
|
||||||
'host_notification_options': 'd,u',
|
'host_notification_options': ['d', 'u'],
|
||||||
'service_notification_options': 'w,c,r',
|
'service_notification_options': ['w', 'c', 'r'],
|
||||||
'host_notification_commands': 'notify-service',
|
'host_notification_commands': ['notify-service'],
|
||||||
'service_notification_commands': 'notify-host'
|
'service_notification_commands': ['notify-host']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'notificationway_name': 'email_all_time',
|
'notificationway_name': 'email_all_time',
|
||||||
'host_notification_period': '24x7',
|
'host_notification_period': '24x7',
|
||||||
'service_notification_period': '24x7',
|
'service_notification_period': '24x7',
|
||||||
'host_notification_options': 'd,r,f,u',
|
'host_notification_options': ['d', 'r', 'f', 'u'],
|
||||||
'service_notification_options': 'w,f,c,r',
|
'service_notification_options': ['w', 'f', 'c', 'r'],
|
||||||
'host_notification_commands': 'notify-service',
|
'host_notification_commands': ['notify-service'],
|
||||||
'service_notification_commands': 'notify-host',
|
'service_notification_commands': ['notify-host'],
|
||||||
'min_business_impact': 5
|
'min_business_impact': 5
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -58,19 +58,19 @@ class TestNotificationWayController(functionalTest.FunctionalTest):
|
|||||||
'notificationway_name': 'email_in_day',
|
'notificationway_name': 'email_in_day',
|
||||||
'host_notification_period': '24x7',
|
'host_notification_period': '24x7',
|
||||||
'service_notification_period': '24x7',
|
'service_notification_period': '24x7',
|
||||||
'host_notification_options': 'd,u',
|
'host_notification_options': ['d', 'u'],
|
||||||
'service_notification_options': 'w,c,r',
|
'service_notification_options': ['w', 'c', 'r'],
|
||||||
'host_notification_commands': 'notify-service',
|
'host_notification_commands': ['notify-service'],
|
||||||
'service_notification_commands': 'notify-host'
|
'service_notification_commands': ['notify-host']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'notificationway_name': 'email_all_time',
|
'notificationway_name': 'email_all_time',
|
||||||
'host_notification_period': '24x7',
|
'host_notification_period': '24x7',
|
||||||
'service_notification_period': '24x7',
|
'service_notification_period': '24x7',
|
||||||
'host_notification_options': 'd,r,f,u',
|
'host_notification_options': ['d', 'r', 'f', 'u'],
|
||||||
'service_notification_options': 'w,f,c,r',
|
'service_notification_options': ['w', 'f', 'c', 'r'],
|
||||||
'host_notification_commands': 'notify-service',
|
'host_notification_commands': ['notify-service'],
|
||||||
'service_notification_commands': 'notify-host',
|
'service_notification_commands': ['notify-host'],
|
||||||
'min_business_impact': 5
|
'min_business_impact': 5
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -86,10 +86,10 @@ class TestNotificationWayController(functionalTest.FunctionalTest):
|
|||||||
'notificationway_name': 'email_all_time',
|
'notificationway_name': 'email_all_time',
|
||||||
'host_notification_period': '24x7',
|
'host_notification_period': '24x7',
|
||||||
'service_notification_period': '24x7',
|
'service_notification_period': '24x7',
|
||||||
'host_notification_options': 'd,r,f,u',
|
'host_notification_options': ['d', 'r', 'f', 'u'],
|
||||||
'service_notification_options': 'w,f,c,r',
|
'service_notification_options': ['w', 'f', 'c', 'r'],
|
||||||
'host_notification_commands': 'notify-service',
|
'host_notification_commands': ['notify-service'],
|
||||||
'service_notification_commands': 'notify-host',
|
'service_notification_commands': ['notify-host'],
|
||||||
'min_business_impact': 5
|
'min_business_impact': 5
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -99,10 +99,10 @@ class TestNotificationWayController(functionalTest.FunctionalTest):
|
|||||||
'notificationway_name': 'test_create_notification',
|
'notificationway_name': 'test_create_notification',
|
||||||
'host_notification_period': '24x7',
|
'host_notification_period': '24x7',
|
||||||
'service_notification_period': '24x7',
|
'service_notification_period': '24x7',
|
||||||
'host_notification_options': 'd,r,f,u',
|
'host_notification_options': ['d', 'r', 'f', 'u'],
|
||||||
'service_notification_options': 'w,f,c,r',
|
'service_notification_options': ['w', 'f', 'c', 'r'],
|
||||||
'host_notification_commands': 'notify-service',
|
'host_notification_commands': ['notify-service'],
|
||||||
'service_notification_commands': 'notify-host',
|
'service_notification_commands': ['notify-host'],
|
||||||
'min_business_impact': 5
|
'min_business_impact': 5
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,10 +146,10 @@ class TestNotificationWayController(functionalTest.FunctionalTest):
|
|||||||
'notificationway_name': 'email_all_time',
|
'notificationway_name': 'email_all_time',
|
||||||
'host_notification_period': '24x7',
|
'host_notification_period': '24x7',
|
||||||
'service_notification_period': '24x7',
|
'service_notification_period': '24x7',
|
||||||
'host_notification_options': 'd,r,f,u',
|
'host_notification_options': ['d', 'r', 'f', 'u'],
|
||||||
'service_notification_options': 'w,f,c,r',
|
'service_notification_options': ['w', 'f', 'c', 'r'],
|
||||||
'host_notification_commands': 'notify-service',
|
'host_notification_commands': ['notify-service'],
|
||||||
'service_notification_commands': 'notify-host',
|
'service_notification_commands': ['notify-host'],
|
||||||
'min_business_impact': 3
|
'min_business_impact': 3
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -27,12 +27,12 @@ class TestRealmsController(functionalTest.FunctionalTest):
|
|||||||
self.realms = [
|
self.realms = [
|
||||||
{
|
{
|
||||||
'realm_name': 'World',
|
'realm_name': 'World',
|
||||||
'realm_members': 'Europe,America,Asia',
|
'realm_members': ['Europe', 'America', 'Asia'],
|
||||||
'default': 0
|
'default': 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'realm_name': 'Anti-world',
|
'realm_name': 'Anti-world',
|
||||||
'realm_members': 'void,black-hole',
|
'realm_members': ['void', 'black-hole'],
|
||||||
'default': 1
|
'default': 1
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -60,7 +60,7 @@ class TestRealmsController(functionalTest.FunctionalTest):
|
|||||||
def test_create_realm(self):
|
def test_create_realm(self):
|
||||||
r = realm.Realm(
|
r = realm.Realm(
|
||||||
realm_name='John',
|
realm_name='John',
|
||||||
realm_members="marie,bob,joe",
|
realm_members=['marie', 'bob', 'joe'],
|
||||||
default=1
|
default=1
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -86,13 +86,13 @@ class TestRealmsController(functionalTest.FunctionalTest):
|
|||||||
self.mongoconnection.shinken.realms.find_one(
|
self.mongoconnection.shinken.realms.find_one(
|
||||||
{'realm_name': 'World'}
|
{'realm_name': 'World'}
|
||||||
)['realm_members'],
|
)['realm_members'],
|
||||||
'Europe,America,Asia'
|
['Europe', 'America', 'Asia']
|
||||||
)
|
)
|
||||||
|
|
||||||
self.put_json(
|
self.put_json(
|
||||||
'/v2/config/realms/World',
|
'/v2/config/realms/World',
|
||||||
{"realm_name": "World",
|
{"realm_name": "World",
|
||||||
"realm_members": "updated",
|
"realm_members": ["updated"],
|
||||||
"default": 0}
|
"default": 0}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -100,5 +100,5 @@ class TestRealmsController(functionalTest.FunctionalTest):
|
|||||||
self.mongoconnection.shinken.realms.find_one(
|
self.mongoconnection.shinken.realms.find_one(
|
||||||
{'realm_name': 'World'}
|
{'realm_name': 'World'}
|
||||||
)['realm_members'],
|
)['realm_members'],
|
||||||
'updated'
|
['updated']
|
||||||
)
|
)
|
||||||
|
@ -27,11 +27,20 @@ class TestServiceGroupsController(functionalTest.FunctionalTest):
|
|||||||
self.groups = [
|
self.groups = [
|
||||||
{
|
{
|
||||||
'servicegroup_name': 'dbservices',
|
'servicegroup_name': 'dbservices',
|
||||||
'members': 'ms1,SQL Server,ms1,SQL Serverc Agent,ms1,SQL DTC',
|
'members': ['ms1',
|
||||||
|
'SQL Server',
|
||||||
|
'ms1',
|
||||||
|
'SQL Serverc Agent',
|
||||||
|
'ms1',
|
||||||
|
'SQL DTC'],
|
||||||
|
'servicegroup_members': []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'servicegroup_name': 'otherservices',
|
'servicegroup_name': 'otherservices',
|
||||||
'members': 'some,other,member',
|
'members': ['some',
|
||||||
|
'other',
|
||||||
|
'member'],
|
||||||
|
'servicegroup_members': []
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
self.mongoconnection.shinken.servicegroups.insert(
|
self.mongoconnection.shinken.servicegroups.insert(
|
||||||
@ -58,7 +67,7 @@ class TestServiceGroupsController(functionalTest.FunctionalTest):
|
|||||||
def test_create_servicegroup(self):
|
def test_create_servicegroup(self):
|
||||||
s = servicegroup.ServiceGroup(
|
s = servicegroup.ServiceGroup(
|
||||||
servicegroup_name='John',
|
servicegroup_name='John',
|
||||||
members="marie,bob,joe",
|
members=['marie', 'bob', 'joe'],
|
||||||
)
|
)
|
||||||
|
|
||||||
self.post_json('/v2/config/servicegroups', s.as_dict())
|
self.post_json('/v2/config/servicegroups', s.as_dict())
|
||||||
@ -83,18 +92,23 @@ class TestServiceGroupsController(functionalTest.FunctionalTest):
|
|||||||
self.mongoconnection.shinken.servicegroups.find_one(
|
self.mongoconnection.shinken.servicegroups.find_one(
|
||||||
{'servicegroup_name': 'dbservices'}
|
{'servicegroup_name': 'dbservices'}
|
||||||
)['members'],
|
)['members'],
|
||||||
'ms1,SQL Server,ms1,SQL Serverc Agent,ms1,SQL DTC'
|
['ms1',
|
||||||
|
'SQL Server',
|
||||||
|
'ms1',
|
||||||
|
'SQL Serverc Agent',
|
||||||
|
'ms1',
|
||||||
|
'SQL DTC']
|
||||||
)
|
)
|
||||||
|
|
||||||
self.put_json(
|
self.put_json(
|
||||||
'/v2/config/servicegroups/dbservices',
|
'/v2/config/servicegroups/dbservices',
|
||||||
{"servicegroup_name": "dbservices",
|
{"servicegroup_name": "dbservices",
|
||||||
"members": "updated"}
|
"members": ["updated"]}
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.mongoconnection.shinken.servicegroups.find_one(
|
self.mongoconnection.shinken.servicegroups.find_one(
|
||||||
{'servicegroup_name': 'dbservices'}
|
{'servicegroup_name': 'dbservices'}
|
||||||
)['members'],
|
)['members'],
|
||||||
'updated'
|
['updated']
|
||||||
)
|
)
|
||||||
|
@ -25,7 +25,7 @@ class TestServiceController(functionalTest.FunctionalTest):
|
|||||||
super(TestServiceController, self).setUp()
|
super(TestServiceController, self).setUp()
|
||||||
self.services = [
|
self.services = [
|
||||||
{
|
{
|
||||||
"host_name": "sample-server1",
|
"host_name": ["sample-server1"],
|
||||||
"service_description": "check-",
|
"service_description": "check-",
|
||||||
"check_command": "check-disk!/dev/sdb1",
|
"check_command": "check-disk!/dev/sdb1",
|
||||||
"max_check_attempts": 5,
|
"max_check_attempts": 5,
|
||||||
@ -34,12 +34,13 @@ class TestServiceController(functionalTest.FunctionalTest):
|
|||||||
"check_period": "24x7",
|
"check_period": "24x7",
|
||||||
"notification_interval": 30,
|
"notification_interval": 30,
|
||||||
"notification_period": "24x7",
|
"notification_period": "24x7",
|
||||||
"contacts": "surveil-ptl,surveil-bob",
|
"contacts": ["surveil-ptl", "surveil-bob"],
|
||||||
"contact_groups": "linux-admins"
|
"contact_groups": ["linux-admins"],
|
||||||
|
"use": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"host_name": "sample-server2",
|
"host_name": ["sample-server2"],
|
||||||
"service_description": "check-disk-sdb",
|
"service_description": "check-disk-sdb2",
|
||||||
"check_command": "check-disk!/dev/sdb1",
|
"check_command": "check-disk!/dev/sdb1",
|
||||||
"max_check_attempts": 5,
|
"max_check_attempts": 5,
|
||||||
"check_interval": 5,
|
"check_interval": 5,
|
||||||
@ -47,12 +48,13 @@ class TestServiceController(functionalTest.FunctionalTest):
|
|||||||
"check_period": "24x7",
|
"check_period": "24x7",
|
||||||
"notification_interval": 30,
|
"notification_interval": 30,
|
||||||
"notification_period": "24x7",
|
"notification_period": "24x7",
|
||||||
"contacts": "surveil-ptl,surveil-bob",
|
"contacts": ["surveil-ptl", "surveil-bob"],
|
||||||
"contact_groups": "linux-admins"
|
"contact_groups": ["linux-admins"],
|
||||||
|
"use": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"host_name": "sample-server3",
|
"host_name": ["sample-server3"],
|
||||||
"service_description": "check-disk-sdb",
|
"service_description": "check-disk-sdb3",
|
||||||
"check_command": "check-disk!/dev/sdb1",
|
"check_command": "check-disk!/dev/sdb1",
|
||||||
"max_check_attempts": 5,
|
"max_check_attempts": 5,
|
||||||
"check_interval": 5,
|
"check_interval": 5,
|
||||||
@ -60,8 +62,9 @@ class TestServiceController(functionalTest.FunctionalTest):
|
|||||||
"check_period": "24x7",
|
"check_period": "24x7",
|
||||||
"notification_interval": 30,
|
"notification_interval": 30,
|
||||||
"notification_period": "24x7",
|
"notification_period": "24x7",
|
||||||
"contacts": "surveil-ptl,surveil-bob",
|
"contacts": ["surveil-ptl", "surveil-bob"],
|
||||||
"contact_groups": "linux-admins"
|
"contact_groups": ["linux-admins"],
|
||||||
|
"use": []
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
self.mongoconnection.shinken.services.insert(
|
self.mongoconnection.shinken.services.insert(
|
||||||
@ -80,8 +83,8 @@ class TestServiceController(functionalTest.FunctionalTest):
|
|||||||
def test_get_all_services_templates(self):
|
def test_get_all_services_templates(self):
|
||||||
self.mongoconnection.shinken.services.insert(
|
self.mongoconnection.shinken.services.insert(
|
||||||
copy.deepcopy(
|
copy.deepcopy(
|
||||||
{"host_name": "sample-server444",
|
{"host_name": ["sample-server444"],
|
||||||
"service_description": "check-disk-sdb",
|
"service_description": "check-disk-sdb2",
|
||||||
"check_command": "check-disk!/dev/sdb1",
|
"check_command": "check-disk!/dev/sdb1",
|
||||||
"max_check_attempts": 5,
|
"max_check_attempts": 5,
|
||||||
"check_interval": 5,
|
"check_interval": 5,
|
||||||
@ -89,9 +92,9 @@ class TestServiceController(functionalTest.FunctionalTest):
|
|||||||
"check_period": "24x7",
|
"check_period": "24x7",
|
||||||
"notification_interval": 30,
|
"notification_interval": 30,
|
||||||
"notification_period": "24x7",
|
"notification_period": "24x7",
|
||||||
"contacts": "surveil-ptl,surveil-bob",
|
"contacts": ["surveil-ptl", "surveil-bob"],
|
||||||
"register": "0",
|
"register": "0",
|
||||||
"contact_groups": "linux-admins"}
|
"contact_groups": ["linux-admins"]}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
response = self.get('/v2/config/services')
|
response = self.get('/v2/config/services')
|
||||||
@ -112,7 +115,7 @@ class TestServiceController(functionalTest.FunctionalTest):
|
|||||||
|
|
||||||
def test_add_service(self):
|
def test_add_service(self):
|
||||||
new_service = {
|
new_service = {
|
||||||
"host_name": "SOMEHOSTNAME",
|
"host_name": ["SOMEHOSTNAME"],
|
||||||
"service_description": "check-new-thing",
|
"service_description": "check-new-thing",
|
||||||
"check_command": "check-disk!/dev/sdb1",
|
"check_command": "check-disk!/dev/sdb1",
|
||||||
"max_check_attempts": 5,
|
"max_check_attempts": 5,
|
||||||
@ -121,8 +124,9 @@ class TestServiceController(functionalTest.FunctionalTest):
|
|||||||
"check_period": "24x7",
|
"check_period": "24x7",
|
||||||
"notification_interval": 30,
|
"notification_interval": 30,
|
||||||
"notification_period": "24x7",
|
"notification_period": "24x7",
|
||||||
"contacts": "surveil-ptl,surveil-bob",
|
"contacts": ["surveil-ptl", "surveil-bob"],
|
||||||
"contact_groups": "linux-admins"
|
"contact_groups": ["linux-admins"],
|
||||||
|
"use": []
|
||||||
}
|
}
|
||||||
response = self.post_json(
|
response = self.post_json(
|
||||||
"/v2/config/services",
|
"/v2/config/services",
|
||||||
|
0
surveil/tests/cmd/__init__.py
Normal file
0
surveil/tests/cmd/__init__.py
Normal file
23
surveil/tests/cmd/nagios_config/config.cfg
Normal file
23
surveil/tests/cmd/nagios_config/config.cfg
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
define host{
|
||||||
|
use generic-host
|
||||||
|
contact_groups admins
|
||||||
|
host_name localhost
|
||||||
|
address localhost
|
||||||
|
_custom_yolo sdfsdf
|
||||||
|
check_interval 324
|
||||||
|
}
|
||||||
|
|
||||||
|
define service {
|
||||||
|
host_name test
|
||||||
|
}
|
||||||
|
|
||||||
|
define timeperiod{
|
||||||
|
timeperiod_name workhours
|
||||||
|
alias Normal Work Hours
|
||||||
|
monday 09:00-17:00
|
||||||
|
tuesday 09:00-17:00
|
||||||
|
wednesday 09:00-17:00
|
||||||
|
thursday 09:00-17:00
|
||||||
|
friday 09:00-17:00
|
||||||
|
}
|
||||||
|
|
3
surveil/tests/cmd/nagios_config/other_file.cfg
Normal file
3
surveil/tests/cmd/nagios_config/other_file.cfg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
define service {
|
||||||
|
host_name hai
|
||||||
|
}
|
92
surveil/tests/cmd/test_surveil_from_nagios.py
Normal file
92
surveil/tests/cmd/test_surveil_from_nagios.py
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
# Copyright 2014 - Savoir-Faire Linux inc.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from surveil.cmd import surveil_from_nagios
|
||||||
|
from surveil.tests import base as base_test
|
||||||
|
|
||||||
|
|
||||||
|
class TestSurveilFromNagios(base_test.BaseTestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.nagios_config_folder = os.path.join(
|
||||||
|
os.path.dirname(os.path.abspath(__file__)),
|
||||||
|
'nagios_config'
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_surveil_from_nagios_config_cfg(self):
|
||||||
|
surveil_cfg = surveil_from_nagios.load_config(
|
||||||
|
self.nagios_config_folder
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assert_count_equal_backport(
|
||||||
|
surveil_cfg,
|
||||||
|
{
|
||||||
|
'hosts': [
|
||||||
|
{
|
||||||
|
'custom_fields': {'_custom_yolo': 'sdfsdf'},
|
||||||
|
'contact_groups': [
|
||||||
|
'admins'
|
||||||
|
],
|
||||||
|
'use': [
|
||||||
|
'generic-host'
|
||||||
|
],
|
||||||
|
'host_name': 'localhost',
|
||||||
|
'check_interval': 324,
|
||||||
|
'address': 'localhost'}
|
||||||
|
],
|
||||||
|
'services': [
|
||||||
|
{
|
||||||
|
'host_name': [
|
||||||
|
'hai'
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'host_name': [
|
||||||
|
'test'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'timeperiods': [
|
||||||
|
{
|
||||||
|
'timeperiod_name': 'workhours',
|
||||||
|
'alias': 'Normal Work Hours',
|
||||||
|
'periods':
|
||||||
|
{
|
||||||
|
'friday': '09:00-17:00',
|
||||||
|
'monday': '09:00-17:00',
|
||||||
|
'thursday': '09:00-17:00',
|
||||||
|
'tuesday': '09:00-17:00',
|
||||||
|
'wednesday': '09:00-17:00'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_load_single_file(self):
|
||||||
|
other_file_path = os.path.join(
|
||||||
|
self.nagios_config_folder,
|
||||||
|
'other_file.cfg'
|
||||||
|
)
|
||||||
|
|
||||||
|
single_file_config = surveil_from_nagios.load_config(
|
||||||
|
other_file_path
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
single_file_config,
|
||||||
|
{'services': [{'host_name': ['hai']}]}
|
||||||
|
)
|
@ -34,7 +34,7 @@ RUN cd /tmp && \
|
|||||||
# mod-surveil
|
# mod-surveil
|
||||||
RUN pip install python-surveilclient==0.11.0
|
RUN pip install python-surveilclient==0.11.0
|
||||||
RUN cd /tmp && \
|
RUN cd /tmp && \
|
||||||
wget -O mod-surveil-config.tar.gz https://github.com/Alignak-monitoring/mod-surveil/archive/8d7e37333de85f5e90d6fe1780e55e4d90515a2f.tar.gz && \
|
wget -O mod-surveil-config.tar.gz https://github.com/Alignak-monitoring/mod-surveil/archive/fdc98b4fc036aa483ecb58459f11f9a87cf2254a.tar.gz && \
|
||||||
tar -zxvf mod-surveil-config.tar.gz && \
|
tar -zxvf mod-surveil-config.tar.gz && \
|
||||||
mv /tmp/mod-surveil-*/alignak/modules/mod_surveil /var/lib/alignak/modules/mod-surveil && \
|
mv /tmp/mod-surveil-*/alignak/modules/mod_surveil /var/lib/alignak/modules/mod-surveil && \
|
||||||
rm -rfv /tmp/mod-surveil*
|
rm -rfv /tmp/mod-surveil*
|
||||||
|
2
tox.ini
2
tox.ini
@ -30,5 +30,5 @@ commands = {posargs}
|
|||||||
commands = python setup.py build_sphinx
|
commands = python setup.py build_sphinx
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
exclude = .venv,.git,.tox,env,dist,*openstack/common*,*lib/python*/,*egg,build,*doc/conf.py,surveil/cmd/pack_upload.py
|
exclude = .venv,.git,.tox,env,dist,*openstack/common*,*lib/python*/,*egg,build,*doc/conf.py,surveil/cmd/pack_upload.py,surveil/cmd/surveil_from_nagios.py
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user