diff --git a/surveil/api/datamodel/config/host.py b/surveil/api/datamodel/config/host.py index 476cc95..7d28dce 100644 --- a/surveil/api/datamodel/config/host.py +++ b/surveil/api/datamodel/config/host.py @@ -22,7 +22,7 @@ class Host(types.Base): host_name = wsme.wsattr(wtypes.text, mandatory=True) """The name of the host""" - address = wsme.wsattr(wtypes.text, mandatory=True) + 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) diff --git a/surveil/api/handlers/config/businessimpactmodulation_handler.py b/surveil/api/handlers/config/businessimpactmodulation_handler.py index 00943eb..7254f9d 100644 --- a/surveil/api/handlers/config/businessimpactmodulation_handler.py +++ b/surveil/api/handlers/config/businessimpactmodulation_handler.py @@ -37,7 +37,8 @@ class BusinessImpactModulationHandler(handler.Handler): self.request.mongo_connection.shinken.businessimpactmodulations.update( {"business_impact_modulation_name": name}, - modulation_dict + {"$set": modulation_dict}, + upsert=True ) def delete(self, name): diff --git a/surveil/api/handlers/config/checkmodulation_handler.py b/surveil/api/handlers/config/checkmodulation_handler.py index b3f4881..b2b51b2 100644 --- a/surveil/api/handlers/config/checkmodulation_handler.py +++ b/surveil/api/handlers/config/checkmodulation_handler.py @@ -34,7 +34,8 @@ class CheckModulationHandler(handler.Handler): self.request.mongo_connection.shinken.checkmodulations.update( {"checkmodulation_name": checkmodulation_name}, - checkmodulation_dict + {"$set": checkmodulation_dict}, + upsert=True ) def delete(self, checkmodulation_name): diff --git a/surveil/api/handlers/config/command_handler.py b/surveil/api/handlers/config/command_handler.py index fccb8aa..1bf7d8f 100644 --- a/surveil/api/handlers/config/command_handler.py +++ b/surveil/api/handlers/config/command_handler.py @@ -34,7 +34,8 @@ class CommandHandler(handler.Handler): self.request.mongo_connection.shinken.commands.update( {"command_name": command_name}, - command_dict + {"$set": command_dict}, + upsert=True ) def delete(self, command_name): diff --git a/surveil/api/handlers/config/contact_handler.py b/surveil/api/handlers/config/contact_handler.py index 4744697..65bd6ec 100644 --- a/surveil/api/handlers/config/contact_handler.py +++ b/surveil/api/handlers/config/contact_handler.py @@ -35,7 +35,8 @@ class ContactHandler(handler.Handler): self.request.mongo_connection.shinken.contacts.update( {"contact_name": contact_name}, - contact_dict + {"$set": contact_dict}, + upsert=True ) def delete(self, contact_name): diff --git a/surveil/api/handlers/config/contactgroup_handler.py b/surveil/api/handlers/config/contactgroup_handler.py index e3353cf..c6d6bed 100644 --- a/surveil/api/handlers/config/contactgroup_handler.py +++ b/surveil/api/handlers/config/contactgroup_handler.py @@ -35,7 +35,8 @@ class ContactGroupHandler(handler.Handler): self.request.mongo_connection.shinken.contactgroups.update( {"contactgroup_name": group_name}, - group_dict + {"$set": group_dict}, + upsert=True ) def delete(self, group_name): diff --git a/surveil/api/handlers/config/host_handler.py b/surveil/api/handlers/config/host_handler.py index 4c6497a..5570d99 100644 --- a/surveil/api/handlers/config/host_handler.py +++ b/surveil/api/handlers/config/host_handler.py @@ -35,7 +35,8 @@ class HostHandler(handler.Handler): self.request.mongo_connection.shinken.hosts.update( {"host_name": host_name}, - host_dict + {"$set": host_dict}, + upsert=True ) def delete(self, host_name): diff --git a/surveil/api/handlers/config/hostgroup_handler.py b/surveil/api/handlers/config/hostgroup_handler.py index 62e229c..b469b90 100644 --- a/surveil/api/handlers/config/hostgroup_handler.py +++ b/surveil/api/handlers/config/hostgroup_handler.py @@ -35,7 +35,8 @@ class HostGroupHandler(handler.Handler): self.request.mongo_connection.shinken.hostgroups.update( {"hostgroup_name": group_name}, - group_dict + {"$set": group_dict}, + upsert=True ) def delete(self, group_name): diff --git a/surveil/api/handlers/config/macromodulation_handler.py b/surveil/api/handlers/config/macromodulation_handler.py index ca24985..66ff732 100644 --- a/surveil/api/handlers/config/macromodulation_handler.py +++ b/surveil/api/handlers/config/macromodulation_handler.py @@ -35,7 +35,8 @@ class MacroModulationHandler(handler.Handler): self.request.mongo_connection.shinken.macromodulations.update( {"macromodulation_name": modulation_name}, - modulation_dict + {"$set": modulation_dict}, + upsert=True ) def delete(self, modulation_name): diff --git a/surveil/api/handlers/config/notificationway_handler.py b/surveil/api/handlers/config/notificationway_handler.py index 2efb56b..84d809d 100644 --- a/surveil/api/handlers/config/notificationway_handler.py +++ b/surveil/api/handlers/config/notificationway_handler.py @@ -33,7 +33,8 @@ class NotificationWayHandler(handler.Handler): self.request.mongo_connection.shinken.notificationways.update( {"notificationway_name": notificationway_name}, - notificationway_dict + {"$set": notificationway_dict}, + upsert=True ) def delete(self, notificationway_name): diff --git a/surveil/api/handlers/config/realm_handler.py b/surveil/api/handlers/config/realm_handler.py index 7481bd1..da73b12 100644 --- a/surveil/api/handlers/config/realm_handler.py +++ b/surveil/api/handlers/config/realm_handler.py @@ -35,7 +35,8 @@ class RealmHandler(handler.Handler): self.request.mongo_connection.shinken.realms.update( {"realm_name": realm_name}, - realm_dict + {"$set": realm_dict}, + upsert=True ) def delete(self, realm_name): diff --git a/surveil/api/handlers/config/service_handler.py b/surveil/api/handlers/config/service_handler.py index 56ba06a..315fbc6 100644 --- a/surveil/api/handlers/config/service_handler.py +++ b/surveil/api/handlers/config/service_handler.py @@ -35,7 +35,8 @@ class ServiceHandler(handler.Handler): self.request.mongo_connection.shinken.hosts.update( {"host_name": id}, - host_dict + {"$set": host_dict}, + upsert=True ) def delete(self, host_name, service_description): diff --git a/surveil/api/handlers/config/servicegroup_handler.py b/surveil/api/handlers/config/servicegroup_handler.py index d102c4e..dccbebd 100644 --- a/surveil/api/handlers/config/servicegroup_handler.py +++ b/surveil/api/handlers/config/servicegroup_handler.py @@ -35,7 +35,8 @@ class ServiceGroupHandler(handler.Handler): self.request.mongo_connection.shinken.servicegroups.update( {"servicegroup_name": group_name}, - group_dict + {"$set": group_dict}, + upsert=True ) def delete(self, group_name): diff --git a/surveil/api/handlers/config/timeperiod_handler.py b/surveil/api/handlers/config/timeperiod_handler.py index c8bfbdf..7edb3c7 100644 --- a/surveil/api/handlers/config/timeperiod_handler.py +++ b/surveil/api/handlers/config/timeperiod_handler.py @@ -35,7 +35,8 @@ class TimePeriodHandler(handler.Handler): self.request.mongo_connection.shinken.timeperiods.update( {"timeperiod_name": timeperiod_name}, - timeperiod_dict + {"$set": timeperiod_dict}, + upsert=True ) def delete(self, timeperiod_name): diff --git a/surveil/tests/api/controllers/v2/config/test_hosts.py b/surveil/tests/api/controllers/v2/config/test_hosts.py index 53a62c5..200a12e 100644 --- a/surveil/tests/api/controllers/v2/config/test_hosts.py +++ b/surveil/tests/api/controllers/v2/config/test_hosts.py @@ -45,7 +45,8 @@ class TestHostController(functionalTest.FunctionalTest): "host_name": "bogus-router333", "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" + "notification_interval": 30, "notification_period": "24x7", + 'use': 'test' }, ] self.mongoconnection.shinken.hosts.insert( @@ -133,14 +134,8 @@ class TestHostController(functionalTest.FunctionalTest): def test_update_host(self): put_host = { - u"host_name": u"bogus-router333", - u"address": u"newputaddress", - u"max_check_attempts": 222225, - u"check_period": u"newtimeperiod", - u"contacts": u"aaa,bbb", - u"contact_groups": u"newgroup", - u"notification_interval": 333, - u"notification_period": u"newnotificationperiod" + u'host_name': u'bogus-router333', + u'contacts': u'newcontacts', } response = self.put_json( "/v2/config/hosts/bogus-router333", params=put_host @@ -152,7 +147,19 @@ class TestHostController(functionalTest.FunctionalTest): ) ) - self.assertEqual(put_host, mongo_host.as_dict()) + expected = { + 'address': u'192.168.1.254', + 'check_period': u'24x7', + 'notification_interval': 30, + 'contacts': u'newcontacts', + 'notification_period': u'24x7', + 'contact_groups': u'', + 'host_name': u'bogus-router333', + 'max_check_attempts': 3, + 'use': u'test' + } + + self.assertEqual(expected, mongo_host.as_dict()) self.assertEqual(response.status_int, 204) def test_delete_host(self):