mod-mongodb -> mod-surveil-config
Change-Id: I77fcce69b32ed74b9999f9ee41ac8278eb2039dc
This commit is contained in:
parent
0e4b11eb0c
commit
b5844c86cd
@ -51,6 +51,9 @@ ENV SURVEIL_OS_USERNAME=admin
|
||||
ENV SURVEIL_OS_PASSWORD=password
|
||||
ENV SURVEIL_OS_TENANT_NAME=admin
|
||||
|
||||
# Surveil API
|
||||
EXPOSE 5311
|
||||
|
||||
CMD cd /opt/surveil && \
|
||||
./setup.sh && \
|
||||
((sleep 40 && surveil-init --influxdb --packs --mongodb) &) && \
|
||||
|
@ -1,3 +1,9 @@
|
||||
ambassador:
|
||||
image: cpuguy83/docker-grand-ambassador
|
||||
volumes:
|
||||
- "/var/run/docker.sock:/var/run/docker.sock"
|
||||
command: "-name surveil_surveil_1 -name surveil_alignak_1"
|
||||
|
||||
surveil:
|
||||
build: .
|
||||
links:
|
||||
@ -19,6 +25,7 @@ alignak:
|
||||
- mongo
|
||||
- influxdb
|
||||
- redis
|
||||
- "ambassador:surveil"
|
||||
ports:
|
||||
- "7767:7767"
|
||||
environment:
|
||||
|
@ -115,11 +115,13 @@ class HostsController(rest.RestController):
|
||||
return HostController(host_name), remainder
|
||||
|
||||
@util.policy_enforce(['authenticated'])
|
||||
@wsme_pecan.wsexpose([host.Host])
|
||||
def get_all(self):
|
||||
@wsme_pecan.wsexpose([host.Host], int)
|
||||
def get_all(self, templates=0):
|
||||
"""Returns all hosts."""
|
||||
handler = host_handler.HostHandler(pecan.request)
|
||||
hosts = handler.get_all()
|
||||
hosts = handler.get_all(
|
||||
templates=bool(templates)
|
||||
)
|
||||
return hosts
|
||||
|
||||
@util.policy_enforce(['authenticated'])
|
||||
|
@ -24,11 +24,13 @@ from surveil.common import util
|
||||
class ServicesController(rest.RestController):
|
||||
|
||||
@util.policy_enforce(['authenticated'])
|
||||
@wsme_pecan.wsexpose([service.Service])
|
||||
def get_all(self):
|
||||
@wsme_pecan.wsexpose([service.Service], int)
|
||||
def get_all(self, templates=0):
|
||||
"""Returns all services."""
|
||||
handler = service_handler.ServiceHandler(pecan.request)
|
||||
services = handler.get_all()
|
||||
services = handler.get_all(
|
||||
templates=bool(templates)
|
||||
)
|
||||
return services
|
||||
|
||||
@util.policy_enforce(['authenticated'])
|
||||
|
@ -33,6 +33,8 @@ class Command(types.Base):
|
||||
command_line = wsme.wsattr(wtypes.text, mandatory=True)
|
||||
"""This directive is used to define what is actually executed by Shinken"""
|
||||
|
||||
module_type = wsme.wsattr(wtypes.text, mandatory=False)
|
||||
|
||||
@classmethod
|
||||
def sample(cls):
|
||||
return cls(
|
||||
|
@ -25,25 +25,32 @@ class Host(types.Base):
|
||||
address = wsme.wsattr(wtypes.text, mandatory=False)
|
||||
"""The address of the host. Normally, this is an IP address."""
|
||||
|
||||
max_check_attempts = wsme.wsattr(int, mandatory=False, default=3)
|
||||
max_check_attempts = wsme.wsattr(int, mandatory=False)
|
||||
|
||||
check_period = wsme.wsattr(wtypes.text, mandatory=False, default='24x7')
|
||||
check_period = wsme.wsattr(wtypes.text, mandatory=False)
|
||||
"""The time period during which active checks of this host can be made."""
|
||||
|
||||
contacts = wsme.wsattr(wtypes.text, mandatory=False, default='')
|
||||
contacts = wsme.wsattr(wtypes.text, mandatory=False)
|
||||
"""A list of the short names of the contacts that should be notified."""
|
||||
|
||||
contact_groups = wsme.wsattr(wtypes.text, mandatory=False, default='')
|
||||
contact_groups = wsme.wsattr(wtypes.text, mandatory=False)
|
||||
"""List of the short names of the contact groups that should be notified"""
|
||||
|
||||
notification_interval = wsme.wsattr(int, mandatory=False, default=30)
|
||||
notification_interval = wsme.wsattr(int, mandatory=False)
|
||||
|
||||
notification_period = wsme.wsattr(wtypes.text, mandatory=False,
|
||||
default='24x7')
|
||||
notification_period = wsme.wsattr(wtypes.text, mandatory=False)
|
||||
|
||||
use = wsme.wsattr(wtypes.text, mandatory=False)
|
||||
"""The template to use for this host"""
|
||||
|
||||
name = wsme.wsattr(wtypes.text, mandatory=False)
|
||||
|
||||
register = wsme.wsattr(wtypes.text, mandatory=False)
|
||||
|
||||
check_interval = wsme.wsattr(int, mandatory=False)
|
||||
|
||||
retry_interval = wsme.wsattr(int, mandatory=False)
|
||||
|
||||
# TODO(aviau): Custom fields starting without '_' should raise an error.
|
||||
custom_fields = wsme.wsattr(
|
||||
wtypes.DictType(wtypes.text, wtypes.text),
|
||||
@ -51,28 +58,6 @@ class Host(types.Base):
|
||||
)
|
||||
"""Custom fields for the host"""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(Host, self).__init__(**kwargs)
|
||||
|
||||
# Custom fields start with '_'. Detect them ans assign them.
|
||||
custom_fields = [i for i in kwargs.items()
|
||||
if (isinstance(i[0], str)
|
||||
or isinstance(i[0], unicode))
|
||||
and i[0][0] == '_']
|
||||
|
||||
if len(custom_fields) > 0:
|
||||
self.custom_fields = {}
|
||||
for item in custom_fields:
|
||||
self.custom_fields[item[0]] = item[1]
|
||||
|
||||
def as_dict(self):
|
||||
host_dict = super(Host, self).as_dict()
|
||||
custom_fields = host_dict.pop("custom_fields", None)
|
||||
if custom_fields:
|
||||
for item in custom_fields.items():
|
||||
host_dict[item[0]] = item[1]
|
||||
return host_dict
|
||||
|
||||
@classmethod
|
||||
def sample(cls):
|
||||
return cls(
|
||||
|
@ -43,6 +43,12 @@ class Service(types.Base):
|
||||
|
||||
passive_checks_enabled = wsme.wsattr(wtypes.text, mandatory=False)
|
||||
|
||||
use = wsme.wsattr(wtypes.text, mandatory=False)
|
||||
|
||||
name = wsme.wsattr(wtypes.text, mandatory=False)
|
||||
|
||||
register = wsme.wsattr(wtypes.text, mandatory=False)
|
||||
|
||||
@classmethod
|
||||
def sample(cls):
|
||||
return cls(
|
||||
|
@ -52,9 +52,12 @@ class ServiceHandler(handler.Handler):
|
||||
data.as_dict()
|
||||
)
|
||||
|
||||
def get_all(self, host_name=None):
|
||||
def get_all(self, host_name=None, templates=False):
|
||||
"""Return all services."""
|
||||
filters = {"register": {"$ne": "0"}}
|
||||
if templates is True:
|
||||
filters = {}
|
||||
else:
|
||||
filters = {"register": {"$ne": "0"}}
|
||||
|
||||
if host_name is not None:
|
||||
filters['host_name'] = host_name
|
||||
|
@ -66,11 +66,15 @@ class MongoObjectHandler(handler.Handler):
|
||||
resource.as_dict()
|
||||
)
|
||||
|
||||
def get_all(self):
|
||||
def get_all(self, templates=False):
|
||||
"""Return all resources."""
|
||||
if templates is True:
|
||||
filters = {}
|
||||
else:
|
||||
filters = {"register": {"$ne": "0"}}
|
||||
|
||||
resources = [r for r
|
||||
in self._get_resource_collection()
|
||||
.find({"register": {"$ne": "0"}},
|
||||
{'_id': 0})]
|
||||
.find(filters, {'_id': 0})]
|
||||
resources = [self.resource_datamodel(**r) for r in resources]
|
||||
return resources
|
||||
|
@ -30,7 +30,6 @@ class TestHostController(functionalTest.FunctionalTest):
|
||||
"max_check_attempts": 5, "check_period": "24x7",
|
||||
"contacts": "admin,carl", "contact_groups": "router-admins",
|
||||
"notification_interval": 30, "notification_period": "24x7",
|
||||
"_CRITICAL": "10"
|
||||
},
|
||||
{
|
||||
"host_name": "bogus-router2", "address": "192.168.1.254",
|
||||
@ -72,21 +71,13 @@ class TestHostController(functionalTest.FunctionalTest):
|
||||
def test_get_all_hosts(self):
|
||||
response = self.get('/v2/config/hosts')
|
||||
|
||||
# Adjust self.host content to reflect custom_fields sub-dict
|
||||
c_fields = {}
|
||||
for h in self.hosts:
|
||||
if '_CRITICAL' in h.keys():
|
||||
c_fields['_CRITICAL'] = h['_CRITICAL']
|
||||
h.pop('_CRITICAL')
|
||||
h['custom_fields'] = c_fields
|
||||
|
||||
self.assert_count_equal_backport(
|
||||
json.loads(response.body.decode()),
|
||||
self.hosts
|
||||
)
|
||||
self.assertEqual(response.status_int, 200)
|
||||
|
||||
def test_get_all_hosts_no_templates(self):
|
||||
def test_get_all_hosts_templates(self):
|
||||
self.mongoconnection.shinken.hosts.insert(
|
||||
copy.deepcopy(
|
||||
{"host_name": "bogus-router", "address": "192.168.1.254",
|
||||
@ -110,6 +101,13 @@ class TestHostController(functionalTest.FunctionalTest):
|
||||
json.loads(response.body.decode()),
|
||||
self.hosts
|
||||
)
|
||||
|
||||
response = self.get('/v2/config/hosts', params={'templates': 1})
|
||||
self.assertEqual(
|
||||
len(json.loads(response.body.decode())),
|
||||
len(self.hosts) + 1
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_int, 200)
|
||||
|
||||
def test_get_specific_host(self):
|
||||
@ -121,14 +119,6 @@ class TestHostController(functionalTest.FunctionalTest):
|
||||
)
|
||||
self.assertEqual(response.status_int, 200)
|
||||
|
||||
def test_get_specific_host_custom_field(self):
|
||||
response = self.get('/v2/config/hosts/bogus-router')
|
||||
my_host = json.loads(response.body.decode())
|
||||
|
||||
self.assertIn("custom_fields", my_host.keys())
|
||||
self.assertNotIn("_CRITICAL", my_host.keys())
|
||||
self.assertIsNone(my_host.get("_CRITICAL"))
|
||||
|
||||
def test_update_host(self):
|
||||
put_host = {
|
||||
u'host_name': u'bogus-router333',
|
||||
@ -150,9 +140,9 @@ class TestHostController(functionalTest.FunctionalTest):
|
||||
'notification_interval': 30,
|
||||
'contacts': u'newcontacts',
|
||||
'notification_period': u'24x7',
|
||||
'contact_groups': u'',
|
||||
'contact_groups': u'router-admins',
|
||||
'host_name': u'bogus-router333',
|
||||
'max_check_attempts': 3,
|
||||
'max_check_attempts': 5,
|
||||
'use': u'test'
|
||||
}
|
||||
|
||||
@ -187,56 +177,6 @@ class TestHostController(functionalTest.FunctionalTest):
|
||||
self.assertTrue(new_host in hosts)
|
||||
self.assertEqual(response.status_int, 201)
|
||||
|
||||
def test_add_host_custom_fields(self):
|
||||
my_host = {
|
||||
"host_name": "custom_field_host", "address": "192.168.1.254",
|
||||
"max_check_attempts": 5, "check_period": "24x7",
|
||||
"contacts": "admin,carl", "contact_groups": "router-admins",
|
||||
"notification_interval": 30, "notification_period": "24x7",
|
||||
"_TEST_CUSTOM_FIELD": "10"
|
||||
}
|
||||
|
||||
self.mongoconnection.shinken.hosts.insert(my_host)
|
||||
mongo_host = self.mongoconnection.shinken.hosts.find_one(
|
||||
{"host_name": "custom_field_host"}
|
||||
)
|
||||
# In-MongoDB representation should hold custom fields similarly to
|
||||
# Shinken:
|
||||
#
|
||||
# define host {
|
||||
# _CUSTOM value
|
||||
# }
|
||||
# (no "custom_fields" sub-dict)
|
||||
self.assertNotIn("custom_fields", mongo_host.keys())
|
||||
self.assertIn("_TEST_CUSTOM_FIELD", mongo_host.keys())
|
||||
self.assertIsNotNone(mongo_host["_TEST_CUSTOM_FIELD"])
|
||||
|
||||
def test_post_add_host_custom_fields(self):
|
||||
my_host = {
|
||||
"host_name": "custom_field_host", "address": "192.168.1.254",
|
||||
"max_check_attempts": 5, "check_period": "24x7",
|
||||
"contacts": "admin,carl", "contact_groups": "router-admins",
|
||||
"notification_interval": 30, "notification_period": "24x7",
|
||||
"custom_fields": {
|
||||
"_TEST_CUSTOM_FIELD": "10"
|
||||
}
|
||||
}
|
||||
|
||||
self.post_json('/v2/config/hosts', my_host)
|
||||
mongo_host = self.mongoconnection.shinken.hosts.find_one(
|
||||
{"host_name": "custom_field_host"}
|
||||
)
|
||||
# In-MongoDB representation should hold custom fields similarly to
|
||||
# Shinken:
|
||||
#
|
||||
# define host {
|
||||
# _CUSTOM value
|
||||
# }
|
||||
# (no "custom_fields" sub-dict)
|
||||
self.assertNotIn("custom_fields", mongo_host.keys())
|
||||
self.assertIn("_TEST_CUSTOM_FIELD", mongo_host.keys())
|
||||
self.assertIsNotNone(mongo_host["_TEST_CUSTOM_FIELD"])
|
||||
|
||||
def test_get_associated_services(self):
|
||||
response = self.get('/v2/config/hosts/bogus-router/services')
|
||||
|
||||
|
@ -77,7 +77,7 @@ class TestServiceController(functionalTest.FunctionalTest):
|
||||
)
|
||||
self.assertEqual(response.status_int, 200)
|
||||
|
||||
def test_get_all_services_no_templates(self):
|
||||
def test_get_all_services_templates(self):
|
||||
self.mongoconnection.shinken.services.insert(
|
||||
copy.deepcopy(
|
||||
{"host_name": "sample-server3",
|
||||
@ -100,6 +100,14 @@ class TestServiceController(functionalTest.FunctionalTest):
|
||||
json.loads(response.body.decode()),
|
||||
self.services
|
||||
)
|
||||
|
||||
response = self.get('/v2/config/services', params={"templates": 1})
|
||||
|
||||
self.assertEqual(
|
||||
len(json.loads(response.body.decode())),
|
||||
len(self.services) + 1
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_int, 200)
|
||||
|
||||
def test_add_service(self):
|
||||
|
@ -31,13 +31,14 @@ RUN cd /tmp && \
|
||||
mv /tmp/mod-booster-nrpe-*/module /var/lib/alignak/modules/mod-booster-nrpe && \
|
||||
rm -rfv /tmp/mod-booster-nrpe*
|
||||
|
||||
# mod-mongodb
|
||||
RUN pip install pymongo==3.0.2
|
||||
# mod-surveil-config
|
||||
RUN apt-get update && apt-get install -y git
|
||||
RUN pip install -e git+https://github.com/aviau/python-surveilclient.git@templates#egg=python-surveilclient
|
||||
RUN cd /tmp && \
|
||||
wget -O mod-mongodb.tar.gz https://github.com/shinken-monitoring/mod-mongodb/archive/5396fded1c56d57202236d1236703a160aec7375.tar.gz && \
|
||||
tar -zxvf mod-mongodb.tar.gz && \
|
||||
mv /tmp/mod-mongodb-*/module /var/lib/alignak/modules/mod-mongodb && \
|
||||
rm -rfv /tmp/mod-mongodb*
|
||||
wget -O mod-surveil-config.tar.gz https://github.com/Alignak-monitoring/mod-surveil-config/archive/6331d3626fd92deaeb5e372c5cdb1eedd8b09d9b.tar.gz && \
|
||||
tar -zxvf mod-surveil-config.tar.gz && \
|
||||
mv /tmp/mod-surveil-config-*/alignak/modules/mod_surveil_config /var/lib/alignak/modules/mod-surveil-config && \
|
||||
rm -rfv /tmp/mod-surveil-config*
|
||||
|
||||
# mod-influxdb
|
||||
RUN pip install influxdb==2.3.0
|
||||
@ -55,6 +56,7 @@ RUN cd /tmp && \
|
||||
rm -rfv /tmp/mod-ws-arbiter*
|
||||
|
||||
# mod-mongo-live-config
|
||||
RUN pip install pymongo==3.0.2
|
||||
RUN cd /tmp && \
|
||||
wget -O mod-mongo-live-config.tar.gz https://github.com/savoirfairelinux/mod-mongo-live-config/archive/0.3.2.tar.gz && \
|
||||
tar -zxvf mod-mongo-live-config.tar.gz && \
|
||||
|
@ -35,7 +35,7 @@ define arbiter {
|
||||
# - FileTag = Tag an host if it's on a flat file
|
||||
# - CSVTag = Tag an host from the content of a CSV file
|
||||
|
||||
modules mongodb,ws-arbiter,mongo_live_config
|
||||
modules surveil_config,ws-arbiter,mongo_live_config
|
||||
#modules named-pipe, mongodb, nsca, VMWare_auto_linking, ws-arbiter, Collectd, mport-landscape, SnmpBooster, AWS
|
||||
|
||||
# Enable https or not
|
||||
|
@ -1,12 +0,0 @@
|
||||
## Module: Mongodb
|
||||
## Loaded by: Arbiter, WebUI
|
||||
# In Arbiter: Read objects in a mongodb database (like hosts or services).
|
||||
# In WebUI: Save/read user preferences.
|
||||
define module {
|
||||
module_name mongodb
|
||||
module_type mongodb
|
||||
uri mongodb://mongo/
|
||||
database shinken
|
||||
#username username ;optional
|
||||
#password password ;optional
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
define module {
|
||||
module_name surveil_config
|
||||
module_type surveil_config
|
||||
surveil_api_url http://surveil:5311/v2
|
||||
surveil_auth_url http://surveil:5311/v2/auth
|
||||
surveil_version 2_0
|
||||
}
|
Loading…
Reference in New Issue
Block a user