Change config objects create/list to use PUT/POST
Change-Id: Ia7010744e293321d2a63073c811111bd4b310b58
This commit is contained in:
parent
3b690e2de0
commit
7118acfdfa
@ -136,38 +136,40 @@ def get_columns(lines, ordered_columns):
|
||||
|
||||
return valid_columns + sorted(columns_dict.keys())
|
||||
|
||||
def create_query(query=None, filters={}, start_time=None, end_time=None,
|
||||
page_size=None, page=None):
|
||||
if query is None:
|
||||
query = {}
|
||||
else:
|
||||
query = json.loads(query)
|
||||
|
||||
if start_time and end_time:
|
||||
query['time_interval'] = {
|
||||
"start_time": start_time,
|
||||
"end_time": end_time
|
||||
}
|
||||
def create_query(**kwargs):
|
||||
|
||||
if 'filters' not in query:
|
||||
query['filters'] = {}
|
||||
query = {}
|
||||
filters = {}
|
||||
paging = {}
|
||||
time = {}
|
||||
|
||||
for filter_type in filters:
|
||||
if 'is' not in query['filters']:
|
||||
query['filters'][filter_type] = {}
|
||||
if kwargs:
|
||||
for arg in kwargs:
|
||||
if arg is 'live_query':
|
||||
query = json.loads(kwargs[arg])
|
||||
elif arg in ['page_size', 'page']:
|
||||
paging[arg] = kwargs[arg]
|
||||
elif arg in ['start_time', 'end_time']:
|
||||
time[arg] = kwargs[arg]
|
||||
else:
|
||||
filters[arg] = [kwargs[arg]]
|
||||
|
||||
for value in filters[filter_type]:
|
||||
if filters[filter_type][value] is not None:
|
||||
query['filters'][filter_type][value] = [
|
||||
filters[filter_type][value]
|
||||
]
|
||||
if time:
|
||||
query["time_interval"] = time
|
||||
|
||||
query['filters'] = json.dumps(query['filters'])
|
||||
if paging:
|
||||
query["paging"] = paging
|
||||
|
||||
if page_size and page:
|
||||
query['paging'] = {
|
||||
'size': page_size,
|
||||
'page': page
|
||||
}
|
||||
if filters:
|
||||
if 'filters' not in query:
|
||||
query["filters"] = {}
|
||||
if 'is' not in query["filters"]:
|
||||
query["filters"]["is"] = filters
|
||||
else:
|
||||
query["filters"]["is"].update(filters)
|
||||
|
||||
if 'filters' in query:
|
||||
query['filters'] = json.dumps(query['filters'])
|
||||
|
||||
return query
|
||||
|
50
surveilclient/tests/common/test_utils.py
Normal file
50
surveilclient/tests/common/test_utils.py
Normal file
@ -0,0 +1,50 @@
|
||||
# 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 json
|
||||
import unittest
|
||||
|
||||
from surveilclient.common import utils
|
||||
|
||||
|
||||
class TestQuery(unittest.TestCase):
|
||||
|
||||
def test_create_live_query(self):
|
||||
expected = {"filters": '{"is": {"host_name": ["toto"]}}',
|
||||
"paging": {"page": 15}}
|
||||
args = {
|
||||
"live_query": '{"filters":{"is":{"host_name":["toto"]}},'
|
||||
'"paging":{"page":15}}'
|
||||
}
|
||||
result = utils.create_query(**args)
|
||||
|
||||
self.assertEqual(json.loads(result["filters"]),
|
||||
json.loads(expected["filters"]))
|
||||
self.assertEqual(result["paging"], expected["paging"])
|
||||
|
||||
def test_add_filters_to_live_query(self):
|
||||
expected = {"filters": '{"is": {"register": ["0"], '
|
||||
'"host_name": ["toto"]}}',
|
||||
"paging": {"page_size": 15}}
|
||||
args = {
|
||||
"live_query": '{"filters":{"is":{"host_name":["toto"]}},'
|
||||
'"paging":{"page":10}}',
|
||||
"register": "0",
|
||||
"page_size": 15
|
||||
}
|
||||
result = utils.create_query(**args)
|
||||
|
||||
self.assertEqual(json.loads(result["filters"]),
|
||||
json.loads(expected["filters"]))
|
||||
self.assertEqual(result["paging"], expected["paging"])
|
@ -23,8 +23,8 @@ class TestBusinessImpactModulations(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_list(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.GET, "http://localhost:5311/v2/config/"
|
||||
"businessimpactmodulations",
|
||||
httpretty.POST, "http://localhost:5311/v2/config/"
|
||||
"businessimpactmodulations",
|
||||
body='[{"business_impact": 1,'
|
||||
'"business_impact_modulation_name": "LowImpactOnDay",'
|
||||
'"modulation_period": "day"},'
|
||||
@ -50,8 +50,8 @@ class TestBusinessImpactModulations(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_create(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.POST, "http://localhost:5311/v2/config/"
|
||||
"businessimpactmodulations",
|
||||
httpretty.PUT, "http://localhost:5311/v2/config/"
|
||||
"businessimpactmodulations",
|
||||
body='{"business_impact": 1,'
|
||||
'"business_impact_modulation_name": "testtt",'
|
||||
'"modulation_period": "day"}'
|
||||
|
@ -22,7 +22,7 @@ class TestCheckModulations(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_create(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.POST, "http://localhost:5311/v2/config/checkmodulations",
|
||||
httpretty.PUT, "http://localhost:5311/v2/config/checkmodulations",
|
||||
body='{"message": "Ack received!"}')
|
||||
|
||||
self.client.config.checkmodulations.create(
|
||||
@ -41,7 +41,7 @@ class TestCheckModulations(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_list(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.GET, "http://localhost:5311/v2/config/checkmodulations",
|
||||
httpretty.POST, "http://localhost:5311/v2/config/checkmodulations",
|
||||
body='[{"checkmodulation_name": "test","check_command": "test",'
|
||||
'"check_period": "test"}]'
|
||||
)
|
||||
|
@ -24,7 +24,7 @@ class TestCommands(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_list(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.GET,
|
||||
httpretty.POST,
|
||||
"http://localhost:5311/v2/config/commands",
|
||||
body='[{"command_name":"myCommand"}]'
|
||||
)
|
||||
@ -37,7 +37,7 @@ class TestCommands(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_create(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.POST, "http://localhost:5311/v2/config/commands",
|
||||
httpretty.PUT, "http://localhost:5311/v2/config/commands",
|
||||
body='{"command_name": "new_command", "command_line": "new_line"}'
|
||||
)
|
||||
|
||||
|
@ -23,7 +23,7 @@ class TestContactGroups(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_list(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.GET, "http://localhost:5311/v2/config/contactgroups",
|
||||
httpretty.POST, "http://localhost:5311/v2/config/contactgroups",
|
||||
body='[{"contactgroup_name": "novell-admins",'
|
||||
'"members": "jdoe,rtobert,tzach"},'
|
||||
'{"contactgroup_name": "linux-adminx",'
|
||||
@ -44,7 +44,7 @@ class TestContactGroups(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_create(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.POST, "http://localhost:5311/v2/config/contactgroups",
|
||||
httpretty.PUT, "http://localhost:5311/v2/config/contactgroups",
|
||||
body='{"contactgroup_name": "John",'
|
||||
'"members": "marie,bob,joe"}'
|
||||
)
|
||||
|
@ -23,7 +23,7 @@ class TestContacts(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_list(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.GET, "http://localhost:5311/v2/config/contacts",
|
||||
httpretty.POST, "http://localhost:5311/v2/config/contacts",
|
||||
body='[{"contact_name": "bobby",'
|
||||
'"email": "bob@bob.com"},'
|
||||
'{"contact_name": "marie",'
|
||||
@ -50,7 +50,7 @@ class TestContacts(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_create(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.POST, "http://localhost:5311/v2/config/contacts",
|
||||
httpretty.PUT, "http://localhost:5311/v2/config/contacts",
|
||||
body='{"contact_name": "John"}'
|
||||
)
|
||||
|
||||
|
@ -23,7 +23,7 @@ class TestHostGroups(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_list(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.GET, "http://localhost:5311/v2/config/hostgroups",
|
||||
httpretty.POST, "http://localhost:5311/v2/config/hostgroups",
|
||||
body='[{"hostgroup_name": "novell-servers",'
|
||||
'"members": "netware1,netware2,netware3,netware4"},'
|
||||
'{"hostgroup_name": "otherservers",'
|
||||
@ -49,7 +49,7 @@ class TestHostGroups(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_create(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.POST, "http://localhost:5311/v2/config/hostgroups",
|
||||
httpretty.PUT, "http://localhost:5311/v2/config/hostgroups",
|
||||
body='{"hostgroup_name": "John",'
|
||||
'"members": "marie,bob,joe"}'
|
||||
)
|
||||
|
@ -24,7 +24,7 @@ class TestHosts(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_list(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.GET, "http://localhost:5311/v2/config/hosts",
|
||||
httpretty.POST, "http://localhost:5311/v2/config/hosts",
|
||||
body='[{"host_name": "host1"}]'
|
||||
)
|
||||
|
||||
@ -38,20 +38,20 @@ class TestHosts(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_list_templates(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.GET, "http://localhost:5311/v2/config/hosts",
|
||||
httpretty.POST, "http://localhost:5311/v2/config/hosts",
|
||||
body='[]'
|
||||
)
|
||||
|
||||
self.client.config.hosts.list(templates=True)
|
||||
self.assertEqual(
|
||||
httpretty.last_request().path,
|
||||
'/v2/config/hosts?templates=1'
|
||||
'/v2/config/hosts?'
|
||||
)
|
||||
|
||||
@httpretty.activate
|
||||
def test_create(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.POST, "http://localhost:5311/v2/config/hosts",
|
||||
httpretty.PUT, "http://localhost:5311/v2/config/hosts",
|
||||
body='{"host_name": "new_host", "address": "192.168.2.1"}'
|
||||
)
|
||||
|
||||
|
@ -23,7 +23,7 @@ class TestMacroModulations(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_list(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.GET, "http://localhost:5311/v2/config/macromodulations",
|
||||
httpretty.POST, "http://localhost:5311/v2/config/macromodulations",
|
||||
body='[{"macromodulation_name": "HighDuringNight",'
|
||||
'"modulation_period": "night",'
|
||||
'"_CRITICAL": 20,'
|
||||
@ -57,7 +57,7 @@ class TestMacroModulations(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_create(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.POST, "http://localhost:5311/v2/config/macromodulations",
|
||||
httpretty.PUT, "http://localhost:5311/v2/config/macromodulations",
|
||||
body='{"macromodulation_name": "TEST_CREATE_MODULATION",'
|
||||
'"modulation_period": "night"}'
|
||||
)
|
||||
|
@ -23,7 +23,7 @@ class TestNotificationWays(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_list(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.GET, "http://localhost:5311/v2/config/notificationways",
|
||||
httpretty.POST, "http://localhost:5311/v2/config/notificationways",
|
||||
body='[{'
|
||||
'"notificationway_name": "email_in_day",'
|
||||
'"host_notification_period": "24x7",'
|
||||
@ -77,7 +77,7 @@ class TestNotificationWays(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_create(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.POST, "http://localhost:5311/v2/config/notificationways",
|
||||
httpretty.PUT, "http://localhost:5311/v2/config/notificationways",
|
||||
body='{'
|
||||
'"notificationway_name": "email_in_day",'
|
||||
'"host_notification_period": "24x7",'
|
||||
|
@ -23,7 +23,7 @@ class TestRealms(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_list(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.GET, "http://localhost:5311/v2/config/realms",
|
||||
httpretty.POST, "http://localhost:5311/v2/config/realms",
|
||||
body='['
|
||||
'{'
|
||||
'"realm_name": "World",'
|
||||
@ -60,7 +60,7 @@ class TestRealms(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_create(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.POST, "http://localhost:5311/v2/config/realms",
|
||||
httpretty.PUT, "http://localhost:5311/v2/config/realms",
|
||||
body='{"realm_name": "John",'
|
||||
'"realm_members":"marie,bob,joe",'
|
||||
'"default":1}'
|
||||
|
@ -23,7 +23,7 @@ class TestServiceGroups(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_list(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.GET, "http://localhost:5311/v2/config/servicegroups",
|
||||
httpretty.POST, "http://localhost:5311/v2/config/servicegroups",
|
||||
body='[{"servicegroup_name": "dbservices",'
|
||||
'"members": "ms1,SQL Server,ms1,'
|
||||
'SQL Serverc Agent,ms1,SQL DTC"},'
|
||||
@ -51,7 +51,7 @@ class TestServiceGroups(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_create(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.POST, "http://localhost:5311/v2/config/servicegroups",
|
||||
httpretty.PUT, "http://localhost:5311/v2/config/servicegroups",
|
||||
body='{"servicegroup_name": "John",'
|
||||
'"members": "marie,bob,joe"}'
|
||||
)
|
||||
|
@ -22,7 +22,7 @@ class TestServices(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_list(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.GET, "http://localhost:5311/v2/config/services",
|
||||
httpretty.POST, "http://localhost:5311/v2/config/services",
|
||||
body='[{"service_name": "service1"}]'
|
||||
)
|
||||
|
||||
@ -36,20 +36,20 @@ class TestServices(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_list_templates(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.GET, "http://localhost:5311/v2/config/services",
|
||||
httpretty.POST, "http://localhost:5311/v2/config/services",
|
||||
body='[{"service_name": "service1"}]'
|
||||
)
|
||||
|
||||
self.client.config.services.list(templates=True)
|
||||
self.assertEqual(
|
||||
httpretty.last_request().path,
|
||||
'/v2/config/services?templates=1'
|
||||
'/v2/config/services?'
|
||||
)
|
||||
|
||||
@httpretty.activate
|
||||
def test_create(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.POST, "http://localhost:5311/v2/config/services",
|
||||
httpretty.PUT, "http://localhost:5311/v2/config/services",
|
||||
body='{"service_name": "new_service"}'
|
||||
)
|
||||
|
||||
|
@ -23,7 +23,7 @@ class TestTimePeriods(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_list(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.GET, "http://localhost:5311/v2/config/timeperiods",
|
||||
httpretty.POST, "http://localhost:5311/v2/config/timeperiods",
|
||||
body='['
|
||||
'{'
|
||||
'"timeperiod_name": "nonworkhours",'
|
||||
@ -61,7 +61,7 @@ class TestTimePeriods(clienttest.ClientTest):
|
||||
@httpretty.activate
|
||||
def test_create(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.POST, "http://localhost:5311/v2/config/timeperiods",
|
||||
httpretty.PUT, "http://localhost:5311/v2/config/timeperiods",
|
||||
body='{"timeperiod_name": "John"}'
|
||||
)
|
||||
|
||||
|
@ -11,7 +11,6 @@
|
||||
# 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 json
|
||||
|
||||
import httpretty
|
||||
|
||||
@ -30,75 +29,11 @@ class TestEvents(clienttest.ClientTest):
|
||||
'"event_type": "ALERT", "output": "Not Ok"}]'
|
||||
)
|
||||
|
||||
events = self.client.status.events.list(host_name='sfl.com',
|
||||
service_description='cpu',
|
||||
event_type='ALERT',
|
||||
page_size=50,
|
||||
page=5)
|
||||
|
||||
filters = json.loads(
|
||||
httpretty.last_request().body.decode())['filters']
|
||||
self.assertEqual(
|
||||
json.loads(filters)['is'],
|
||||
{"service_description": ["cpu"],
|
||||
"host_name": ["sfl.com"], "event_type": ["ALERT"]}
|
||||
)
|
||||
|
||||
paging = json.loads(
|
||||
httpretty.last_request().body.decode())['paging']
|
||||
self.assertEqual(
|
||||
paging,
|
||||
{u"page": 5,
|
||||
u"size": 50}
|
||||
)
|
||||
|
||||
events = self.client.status.events.list()
|
||||
self.assertEqual(
|
||||
events,
|
||||
[{"host_name": "sfl.com", "service_description": "cpu",
|
||||
"event_type": "ALERT", "output": "Ok"},
|
||||
{"host_name": "sfl.com", "service_description": "cpu",
|
||||
"event_type": "ALERT", "output": "Not Ok"}]
|
||||
)
|
||||
|
||||
@httpretty.activate
|
||||
def test_list_with_live_query(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.POST, "http://localhost:5311/v2/status/events",
|
||||
body='[{"host_name": "sfl.com", "service_description": "cpu", '
|
||||
'"event_type": "ALERT", "output": "Ok"},'
|
||||
'{"host_name": "sfl.com", "service_description": "cpu", '
|
||||
'"event_type": "ALERT", "output": "Not Ok"}]'
|
||||
)
|
||||
|
||||
events = self.client.status.events.list(
|
||||
live_query='{"filters": {"is": {"host_name": ["sfl.com"], '
|
||||
'"event_type": ["ALERT"]},'
|
||||
'"isnot": {"service_description": ["load"]}}}',
|
||||
start_time='2015-05-22T13:38:08Z',
|
||||
end_time='2015-05-22T13:42:08Z'
|
||||
)
|
||||
|
||||
filters = json.loads(httpretty.last_request().body.decode())['filters']
|
||||
self.assertEqual(
|
||||
json.loads(filters)['is'],
|
||||
{"host_name": ["sfl.com"], "event_type": ["ALERT"]}
|
||||
)
|
||||
self.assertEqual(
|
||||
json.loads(filters)['isnot'],
|
||||
{"service_description": ["load"]}
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
json.loads(
|
||||
httpretty.last_request().body.decode())['time_interval'],
|
||||
{u"start_time": u"2015-05-22T13:38:08Z",
|
||||
u"end_time": u"2015-05-22T13:42:08Z"}
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
events,
|
||||
[{"host_name": u"sfl.com", "service_description": u"cpu",
|
||||
"event_type": u"ALERT", "output": u"Ok"},
|
||||
{"host_name": u"sfl.com", "service_description": u"cpu",
|
||||
"event_type": u"ALERT", "output": u"Not Ok"}]
|
||||
)
|
||||
)
|
@ -30,9 +30,7 @@ class TestMetrics(clienttest.ClientTest):
|
||||
|
||||
metrics = self.client.status.hosts.metrics.list(
|
||||
'localhost',
|
||||
'load1',
|
||||
start_time='2015-05-22T13:38:08Z',
|
||||
end_time='2015-05-22T13:38:08Z'
|
||||
'load1'
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
@ -56,7 +54,7 @@ class TestMetrics(clienttest.ClientTest):
|
||||
|
||||
metrics = self.client.status.hosts.metrics.list('localhost', 'load1',
|
||||
'load',
|
||||
live_query=live_query
|
||||
query=live_query
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
|
@ -18,17 +18,19 @@ from surveilclient.common import surveil_manager
|
||||
class BusinessImpactModulationsManager(surveil_manager.SurveilManager):
|
||||
base_url = '/config/businessimpactmodulations'
|
||||
|
||||
def list(self):
|
||||
def list(self, query=None):
|
||||
"""Get a list of businessimpactmodulations."""
|
||||
query = query or {}
|
||||
resp, body = self.http_client.json_request(
|
||||
BusinessImpactModulationsManager.base_url, 'GET'
|
||||
BusinessImpactModulationsManager.base_url, 'POST',
|
||||
body=query
|
||||
)
|
||||
return body
|
||||
|
||||
def create(self, **kwargs):
|
||||
"""Create a new businessimpactmodulation."""
|
||||
resp, body = self.http_client.json_request(
|
||||
BusinessImpactModulationsManager.base_url, 'POST',
|
||||
BusinessImpactModulationsManager.base_url, 'PUT',
|
||||
body=kwargs
|
||||
)
|
||||
return body
|
||||
|
@ -18,17 +18,18 @@ from surveilclient.common import surveil_manager
|
||||
class CheckModulationsManager(surveil_manager.SurveilManager):
|
||||
base_url = '/config/checkmodulations'
|
||||
|
||||
def list(self):
|
||||
def list(self, query=None):
|
||||
"""Get a list of checkmodulations."""
|
||||
query = query or {}
|
||||
resp, body = self.http_client.json_request(
|
||||
CheckModulationsManager.base_url, 'GET'
|
||||
CheckModulationsManager.base_url, 'POST', body=query
|
||||
)
|
||||
return body
|
||||
|
||||
def create(self, **kwargs):
|
||||
"""Create a new checkmodulation."""
|
||||
resp, body = self.http_client.json_request(
|
||||
CheckModulationsManager.base_url, 'POST',
|
||||
CheckModulationsManager.base_url, 'PUT',
|
||||
body=kwargs
|
||||
)
|
||||
return body
|
||||
|
@ -18,17 +18,19 @@ from surveilclient.common import surveil_manager
|
||||
class CommandsManager(surveil_manager.SurveilManager):
|
||||
base_url = '/config/commands'
|
||||
|
||||
def list(self):
|
||||
def list(self, query=None):
|
||||
"""Get a list of commands."""
|
||||
query = query or {}
|
||||
resp, body = self.http_client.json_request(
|
||||
CommandsManager.base_url, 'GET'
|
||||
CommandsManager.base_url, 'POST',
|
||||
body=query
|
||||
)
|
||||
return body
|
||||
|
||||
def create(self, **kwargs):
|
||||
"""Create a new command."""
|
||||
resp, body = self.http_client.json_request(
|
||||
CommandsManager.base_url, 'POST',
|
||||
CommandsManager.base_url, 'PUT',
|
||||
body=kwargs
|
||||
)
|
||||
return body
|
||||
|
@ -18,17 +18,19 @@ from surveilclient.common import surveil_manager
|
||||
class ContactGroupsManager(surveil_manager.SurveilManager):
|
||||
base_url = '/config/contactgroups'
|
||||
|
||||
def list(self):
|
||||
def list(self, query=None):
|
||||
"""Get a list of contactgroups."""
|
||||
query = query or {}
|
||||
resp, body = self.http_client.json_request(
|
||||
ContactGroupsManager.base_url, 'GET'
|
||||
ContactGroupsManager.base_url, 'POST',
|
||||
body=query
|
||||
)
|
||||
return body
|
||||
|
||||
def create(self, **kwargs):
|
||||
"""Create a new contactgroup."""
|
||||
resp, body = self.http_client.json_request(
|
||||
ContactGroupsManager.base_url, 'POST',
|
||||
ContactGroupsManager.base_url, 'PUT',
|
||||
body=kwargs
|
||||
)
|
||||
return body
|
||||
|
@ -18,17 +18,18 @@ from surveilclient.common import surveil_manager
|
||||
class ContactsManager(surveil_manager.SurveilManager):
|
||||
base_url = '/config/contacts'
|
||||
|
||||
def list(self):
|
||||
def list(self, query=None):
|
||||
"""Get a list of contacts."""
|
||||
query = query or {}
|
||||
resp, body = self.http_client.json_request(
|
||||
ContactsManager.base_url, 'GET'
|
||||
ContactsManager.base_url, 'POST', body=query
|
||||
)
|
||||
return body
|
||||
|
||||
def create(self, **kwargs):
|
||||
"""Create a new contact."""
|
||||
resp, body = self.http_client.json_request(
|
||||
ContactsManager.base_url, 'POST',
|
||||
ContactsManager.base_url, 'PUT',
|
||||
body=kwargs
|
||||
)
|
||||
return body
|
||||
|
@ -18,17 +18,19 @@ from surveilclient.common import surveil_manager
|
||||
class HostGroupsManager(surveil_manager.SurveilManager):
|
||||
base_url = '/config/hostgroups'
|
||||
|
||||
def list(self):
|
||||
def list(self, query=None):
|
||||
"""Get a list of hostgroups."""
|
||||
query = query or {}
|
||||
resp, body = self.http_client.json_request(
|
||||
HostGroupsManager.base_url, 'GET'
|
||||
HostGroupsManager.base_url, 'POST',
|
||||
body=query
|
||||
)
|
||||
return body
|
||||
|
||||
def create(self, **kwargs):
|
||||
"""Create a new hostgroup."""
|
||||
resp, body = self.http_client.json_request(
|
||||
HostGroupsManager.base_url, 'POST',
|
||||
HostGroupsManager.base_url, 'PUT',
|
||||
body=kwargs
|
||||
)
|
||||
return body
|
||||
|
@ -12,24 +12,38 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
|
||||
from surveilclient.common import surveil_manager
|
||||
|
||||
|
||||
class HostsManager(surveil_manager.SurveilManager):
|
||||
base_url = '/config/hosts'
|
||||
|
||||
def list(self, templates=False):
|
||||
def list(self, query=None, templates=False):
|
||||
"""Get a list of hosts."""
|
||||
query = query or {}
|
||||
if templates:
|
||||
if 'filters' not in query:
|
||||
query["filters"] = '{}'
|
||||
filters = json.loads(query["filters"])
|
||||
temp_filter = {"register": ["0"]}
|
||||
if 'is' not in filters:
|
||||
filters["is"] = temp_filter
|
||||
else:
|
||||
filters["is"].update(temp_filter)
|
||||
query['filters'] = json.dumps(query['filters'])
|
||||
|
||||
resp, body = self.http_client.json_request(
|
||||
HostsManager.base_url, 'GET',
|
||||
params={"templates": int(templates)}
|
||||
HostsManager.base_url, 'POST',
|
||||
body=query
|
||||
)
|
||||
return body
|
||||
|
||||
def create(self, **kwargs):
|
||||
"""Create a new host."""
|
||||
resp, body = self.http_client.json_request(
|
||||
HostsManager.base_url, 'POST',
|
||||
HostsManager.base_url, 'PUT',
|
||||
body=kwargs
|
||||
)
|
||||
return body
|
||||
|
@ -18,17 +18,19 @@ from surveilclient.common import surveil_manager
|
||||
class MacroModulationsManager(surveil_manager.SurveilManager):
|
||||
base_url = '/config/macromodulations'
|
||||
|
||||
def list(self):
|
||||
def list(self, query=None):
|
||||
"""Get a list of macromodulations."""
|
||||
query = query or {}
|
||||
resp, body = self.http_client.json_request(
|
||||
MacroModulationsManager.base_url, 'GET'
|
||||
MacroModulationsManager.base_url, 'POST',
|
||||
body=query
|
||||
)
|
||||
return body
|
||||
|
||||
def create(self, **kwargs):
|
||||
"""Create a new macromodulation."""
|
||||
resp, body = self.http_client.json_request(
|
||||
MacroModulationsManager.base_url, 'POST',
|
||||
MacroModulationsManager.base_url, 'PUT',
|
||||
body=kwargs
|
||||
)
|
||||
return body
|
||||
|
@ -18,17 +18,19 @@ from surveilclient.common import surveil_manager
|
||||
class NotificationWaysManager(surveil_manager.SurveilManager):
|
||||
base_url = '/config/notificationways'
|
||||
|
||||
def list(self):
|
||||
def list(self, query=None):
|
||||
"""Get a list of notificationways."""
|
||||
query = query or {}
|
||||
resp, body = self.http_client.json_request(
|
||||
NotificationWaysManager.base_url, 'GET'
|
||||
NotificationWaysManager.base_url, 'POST',
|
||||
body=query
|
||||
)
|
||||
return body
|
||||
|
||||
def create(self, **kwargs):
|
||||
"""Create a new notificationway."""
|
||||
resp, body = self.http_client.json_request(
|
||||
NotificationWaysManager.base_url, 'POST',
|
||||
NotificationWaysManager.base_url, 'PUT',
|
||||
body=kwargs
|
||||
)
|
||||
return body
|
||||
|
@ -18,17 +18,19 @@ from surveilclient.common import surveil_manager
|
||||
class RealmsManager(surveil_manager.SurveilManager):
|
||||
base_url = '/config/realms'
|
||||
|
||||
def list(self):
|
||||
def list(self, query=None):
|
||||
"""Get a list of realms."""
|
||||
query = query or {}
|
||||
resp, body = self.http_client.json_request(
|
||||
RealmsManager.base_url, 'GET'
|
||||
RealmsManager.base_url, 'POST',
|
||||
body=query
|
||||
)
|
||||
return body
|
||||
|
||||
def create(self, **kwargs):
|
||||
"""Create a new realm."""
|
||||
resp, body = self.http_client.json_request(
|
||||
RealmsManager.base_url, 'POST',
|
||||
RealmsManager.base_url, 'PUT',
|
||||
body=kwargs
|
||||
)
|
||||
return body
|
||||
|
@ -18,17 +18,19 @@ from surveilclient.common import surveil_manager
|
||||
class ServiceGroupsManager(surveil_manager.SurveilManager):
|
||||
base_url = '/config/servicegroups'
|
||||
|
||||
def list(self):
|
||||
def list(self, query=None):
|
||||
"""Get a list of servicegroups."""
|
||||
query = query or {}
|
||||
resp, body = self.http_client.json_request(
|
||||
ServiceGroupsManager.base_url, 'GET'
|
||||
ServiceGroupsManager.base_url, 'POST',
|
||||
body=query
|
||||
)
|
||||
return body
|
||||
|
||||
def create(self, **kwargs):
|
||||
"""Create a new servicegroup."""
|
||||
resp, body = self.http_client.json_request(
|
||||
ServiceGroupsManager.base_url, 'POST',
|
||||
ServiceGroupsManager.base_url, 'PUT',
|
||||
body=kwargs
|
||||
)
|
||||
return body
|
||||
|
@ -12,24 +12,37 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
|
||||
from surveilclient.common import surveil_manager
|
||||
|
||||
|
||||
class ServicesManager(surveil_manager.SurveilManager):
|
||||
base_url = '/config/services'
|
||||
|
||||
def list(self, templates=False):
|
||||
def list(self, query=None, templates=False):
|
||||
"""Get a list of hosts."""
|
||||
query = query or {}
|
||||
if templates:
|
||||
if 'filters' not in query:
|
||||
query["filters"] = '{}'
|
||||
filters = json.loads(query["filters"])
|
||||
temp_filter = {"register": ["0"]}
|
||||
if 'is' not in filters:
|
||||
filters["is"] = temp_filter
|
||||
else:
|
||||
filters["is"].update(temp_filter)
|
||||
query['filters'] = json.dumps(query['filters'])
|
||||
resp, body = self.http_client.json_request(
|
||||
ServicesManager.base_url, 'GET',
|
||||
params={"templates": int(templates)}
|
||||
ServicesManager.base_url, 'POST',
|
||||
body=query
|
||||
)
|
||||
return body
|
||||
|
||||
def create(self, **kwargs):
|
||||
"""Create a new host."""
|
||||
resp, body = self.http_client.json_request(
|
||||
ServicesManager.base_url, 'POST',
|
||||
ServicesManager.base_url, 'PUT',
|
||||
body=kwargs
|
||||
)
|
||||
return body
|
||||
|
@ -18,17 +18,19 @@ from surveilclient.common import surveil_manager
|
||||
class TimePeriodsManager(surveil_manager.SurveilManager):
|
||||
base_url = '/config/timeperiods'
|
||||
|
||||
def list(self):
|
||||
def list(self, query=None):
|
||||
"""Get a list of timeperiods."""
|
||||
query = query or {}
|
||||
resp, body = self.http_client.json_request(
|
||||
TimePeriodsManager.base_url, 'GET'
|
||||
TimePeriodsManager.base_url, 'POST',
|
||||
body=query
|
||||
)
|
||||
return body
|
||||
|
||||
def create(self, **kwargs):
|
||||
"""Create a new timeperiod."""
|
||||
resp, body = self.http_client.json_request(
|
||||
TimePeriodsManager.base_url, 'POST',
|
||||
TimePeriodsManager.base_url, 'PUT',
|
||||
body=kwargs
|
||||
)
|
||||
return body
|
||||
|
@ -27,9 +27,25 @@ def _dict_from_args(args, arg_names):
|
||||
return result
|
||||
|
||||
|
||||
@cliutils.arg("--business_impact_modulation_name",
|
||||
help="New name of the business impact modulation")
|
||||
@cliutils.arg("--business_impact")
|
||||
@cliutils.arg("--modulation_period")
|
||||
@cliutils.arg("--live_query", help="Live query")
|
||||
@cliutils.arg("--page_size", help="Number of returned data")
|
||||
@cliutils.arg("--page", help="Page number")
|
||||
def do_config_businessimpactmodulation_list(sc, args):
|
||||
"""List all config business impact modulations."""
|
||||
businessimpactmodulations = sc.config.businessimpactmodulations.list()
|
||||
arg_names = ['business_impact_modulation_name',
|
||||
'business_impact',
|
||||
'modulation_period',
|
||||
'live_query',
|
||||
'page_size',
|
||||
'page'
|
||||
]
|
||||
arg_dict = _dict_from_args(args, arg_names)
|
||||
lq = utils.create_query(**arg_dict)
|
||||
businessimpactmodulations = sc.config.businessimpactmodulations.list(lq)
|
||||
|
||||
if args.json:
|
||||
print(utils.json_formatter(businessimpactmodulations))
|
||||
@ -110,9 +126,26 @@ def do_config_businessimpactmodulation_delete(sc, args):
|
||||
args.business_impact_modulation_name)
|
||||
|
||||
|
||||
@cliutils.arg("--checkmodulation_name",
|
||||
help="New name of the check modulation")
|
||||
@cliutils.arg("--check_command")
|
||||
@cliutils.arg("--check_period")
|
||||
@cliutils.arg("--live_query", help="Live query")
|
||||
@cliutils.arg("--page_size", help="Number of returned data")
|
||||
@cliutils.arg("--page", help="Page number")
|
||||
def do_config_checkmodulation_list(sc, args):
|
||||
"""List all config check modulations."""
|
||||
checkmodulations = sc.config.checkmodulations.list()
|
||||
arg_names = ['checkmodulation_name',
|
||||
'check_command',
|
||||
'check_period',
|
||||
'live_query',
|
||||
'page_size',
|
||||
'page'
|
||||
]
|
||||
arg_dict = _dict_from_args(args, arg_names)
|
||||
|
||||
lq = utils.create_query(**arg_dict)
|
||||
checkmodulations = sc.config.checkmodulations.list(lq)
|
||||
|
||||
if args.json:
|
||||
print(utils.json_formatter(checkmodulations))
|
||||
@ -185,21 +218,38 @@ def do_config_checkmodulation_delete(sc, args):
|
||||
sc.config.checkmodulations.delete(args.checkmodulation_name)
|
||||
|
||||
|
||||
@cliutils.arg("--command_name", help="New name of the command")
|
||||
@cliutils.arg("--command_line", help="Address of the command")
|
||||
@cliutils.arg("--module_type")
|
||||
@cliutils.arg("--live_query", help="Live query")
|
||||
@cliutils.arg("--page_size", help="Number of returned data")
|
||||
@cliutils.arg("--page", help="Page number")
|
||||
def do_config_command_list(sc, args):
|
||||
"""List all config commands."""
|
||||
commands = sc.config.commands.list()
|
||||
arg_names = ['command_name',
|
||||
'command_line',
|
||||
'module_type',
|
||||
'live_query',
|
||||
'page_size',
|
||||
'page'
|
||||
]
|
||||
arg_dict = _dict_from_args(args, arg_names)
|
||||
lq = utils.create_query(**arg_dict)
|
||||
commands = sc.config.commands.list(lq)
|
||||
|
||||
if args.json:
|
||||
print(utils.json_formatter(commands))
|
||||
else:
|
||||
cols = [
|
||||
'command_name',
|
||||
'command_line'
|
||||
'command_line',
|
||||
'module_type'
|
||||
]
|
||||
|
||||
formatters = {
|
||||
'command_name': lambda x: x.get('command_name', ''),
|
||||
'command_line': lambda x: x.get('command_line', ''),
|
||||
'module_type': lambda x: x.get('module_type', ''),
|
||||
}
|
||||
utils.print_list(commands, cols, formatters=formatters)
|
||||
|
||||
@ -251,9 +301,27 @@ def do_config_command_delete(sc, args):
|
||||
sc.config.commands.delete(args.command_name)
|
||||
|
||||
|
||||
@cliutils.arg("--contactgroup_name", help="New name of the contactgroup")
|
||||
@cliutils.arg("--members")
|
||||
@cliutils.arg("--alias")
|
||||
@cliutils.arg("--contactgroup_members")
|
||||
@cliutils.arg("--live_query", help="Live query")
|
||||
@cliutils.arg("--page_size", help="Number of returned data")
|
||||
@cliutils.arg("--page", help="Page number")
|
||||
def do_config_contactgroup_list(sc, args):
|
||||
"""List all contact groups."""
|
||||
contactgroups = sc.config.contactgroups.list()
|
||||
arg_names = ['contactgroup_name',
|
||||
'members',
|
||||
'alias',
|
||||
'contactgroup_members',
|
||||
'live_query',
|
||||
'page_size',
|
||||
'page'
|
||||
]
|
||||
arg_dict = _dict_from_args(args, arg_names)
|
||||
lq = utils.create_query(**arg_dict)
|
||||
contactgroups = sc.config.contactgroups.list(lq)
|
||||
|
||||
if args.json:
|
||||
print(utils.json_formatter(contactgroups))
|
||||
else:
|
||||
@ -331,9 +399,50 @@ def do_config_contactgroup_delete(sc, args):
|
||||
sc.config.contactgroups.delete(args.contactgroup_name)
|
||||
|
||||
|
||||
@cliutils.arg("--contact_name", help="New name of the contact")
|
||||
@cliutils.arg("--host_notifications_enabled")
|
||||
@cliutils.arg("--service_notifications_enabled")
|
||||
@cliutils.arg("--host_notification_period")
|
||||
@cliutils.arg("--service_notification_period")
|
||||
@cliutils.arg("--host_notification_options")
|
||||
@cliutils.arg("--service_notification_options")
|
||||
@cliutils.arg("--host_notification_commands")
|
||||
@cliutils.arg("--service_notification_commands")
|
||||
@cliutils.arg("--email")
|
||||
@cliutils.arg("--pager")
|
||||
@cliutils.arg("--can_submit_commands")
|
||||
@cliutils.arg("--is_admin")
|
||||
@cliutils.arg("--retain_status_information")
|
||||
@cliutils.arg("--retain_nonstatus_information")
|
||||
@cliutils.arg("--min_business_impact")
|
||||
@cliutils.arg("--live_query", help="Live query")
|
||||
@cliutils.arg("--page_size", help="Number of returned data")
|
||||
@cliutils.arg("--page", help="Page number")
|
||||
def do_config_contact_list(sc, args):
|
||||
"""List all contacts."""
|
||||
contacts = sc.config.contacts.list()
|
||||
arg_names = ['contact_name',
|
||||
'host_notifications_enabled',
|
||||
'service_notifications_enabled',
|
||||
'host_notification_period',
|
||||
'service_notification_period',
|
||||
'host_notification_options',
|
||||
'service_notification_options',
|
||||
'host_notification_commands',
|
||||
'service_notification_commands',
|
||||
'email',
|
||||
'pager',
|
||||
'can_submit_commands',
|
||||
'is_admin',
|
||||
'retain_status_information',
|
||||
'retain_nonstatus_information',
|
||||
'min_business_impact',
|
||||
'live_query',
|
||||
'page_size',
|
||||
'page'
|
||||
]
|
||||
arg_dict = _dict_from_args(args, arg_names)
|
||||
lq = utils.create_query(**arg_dict)
|
||||
contacts = sc.config.contacts.list(lq)
|
||||
if args.json:
|
||||
print(utils.json_formatter(contacts))
|
||||
else:
|
||||
@ -506,9 +615,32 @@ def do_config_contact_delete(sc, args):
|
||||
sc.config.contacts.delete(args.contact_name)
|
||||
|
||||
|
||||
@cliutils.arg("--hostgroup_name", help="New name of the host group")
|
||||
@cliutils.arg("--members")
|
||||
@cliutils.arg("--alias")
|
||||
@cliutils.arg("--hostgroup_members")
|
||||
@cliutils.arg("--notes")
|
||||
@cliutils.arg("--notes_url")
|
||||
@cliutils.arg("--action_url")
|
||||
@cliutils.arg("--live_query", help="Live query")
|
||||
@cliutils.arg("--page_size", help="Number of returned data")
|
||||
@cliutils.arg("--page", help="Page number")
|
||||
def do_config_hostgroup_list(sc, args):
|
||||
"""List all config host groups."""
|
||||
hostgroups = sc.config.hostgroups.list()
|
||||
arg_names = ['hostgroup_name',
|
||||
'members',
|
||||
'alias',
|
||||
'hostgroup_members',
|
||||
'notes',
|
||||
'notes_url',
|
||||
'action_url',
|
||||
'live_query',
|
||||
'page_size',
|
||||
'page'
|
||||
]
|
||||
arg_dict = _dict_from_args(args, arg_names)
|
||||
lq = utils.create_query(**arg_dict)
|
||||
hostgroups = sc.config.hostgroups.list(lq)
|
||||
|
||||
if args.json:
|
||||
print(utils.json_formatter(hostgroups))
|
||||
@ -607,9 +739,46 @@ def do_config_hostgroup_delete(sc, args):
|
||||
sc.config.hostgroups.delete(args.hostgroup_name)
|
||||
|
||||
|
||||
@cliutils.arg("--host_name", help="New name of the host")
|
||||
@cliutils.arg("--address", help="Address of the host")
|
||||
@cliutils.arg("--max_check_attempts")
|
||||
@cliutils.arg("--check_period")
|
||||
@cliutils.arg("--contacts", nargs='+')
|
||||
@cliutils.arg("--contact_groups", nargs='+')
|
||||
@cliutils.arg("--custom_fields")
|
||||
@cliutils.arg("--notification_interval")
|
||||
@cliutils.arg("--notification_period")
|
||||
@cliutils.arg("--use", nargs='+')
|
||||
@cliutils.arg("--name")
|
||||
@cliutils.arg("--register")
|
||||
@cliutils.arg("--check_interval")
|
||||
@cliutils.arg("--retry_interval")
|
||||
@cliutils.arg("--live_query", help="Live query")
|
||||
@cliutils.arg("--page_size", help="Number of returned data")
|
||||
@cliutils.arg("--page", help="Page number")
|
||||
def do_config_host_list(sc, args):
|
||||
"""List all config hosts."""
|
||||
hosts = sc.config.hosts.list()
|
||||
arg_names = ['host_name',
|
||||
'address',
|
||||
'live_query',
|
||||
'page_size',
|
||||
'page',
|
||||
'max_check_attempts',
|
||||
'check_period',
|
||||
'contacts',
|
||||
'contact_groups',
|
||||
'custom_fields',
|
||||
'notification_interval',
|
||||
'notification_period',
|
||||
'use',
|
||||
'name',
|
||||
'register',
|
||||
'check_interval',
|
||||
'retry_interval'
|
||||
]
|
||||
arg_dict = _dict_from_args(args, arg_names)
|
||||
lq = utils.create_query(**arg_dict)
|
||||
hosts = sc.config.hosts.list(lq)
|
||||
|
||||
if args.json:
|
||||
print(utils.json_formatter(hosts))
|
||||
@ -724,9 +893,24 @@ def do_config_host_delete(sc, args):
|
||||
sc.config.hosts.delete(args.host_name)
|
||||
|
||||
|
||||
@cliutils.arg("--macromodulation_name", help="New name of the macromodulation")
|
||||
@cliutils.arg("--modulation_period")
|
||||
@cliutils.arg("--macros")
|
||||
@cliutils.arg("--live_query", help="Live query")
|
||||
@cliutils.arg("--page_size", help="Number of returned data")
|
||||
@cliutils.arg("--page", help="Page number")
|
||||
def do_config_macromodulation_list(sc, args):
|
||||
"""List all config macromodulations."""
|
||||
macromodulations = sc.config.macromodulations.list()
|
||||
arg_names = ['macromodulation_name',
|
||||
'modulation_period',
|
||||
'macros'
|
||||
'live_query',
|
||||
'page_size',
|
||||
'page'
|
||||
]
|
||||
arg_dict = _dict_from_args(args, arg_names)
|
||||
lq = utils.create_query(**arg_dict)
|
||||
macromodulations = sc.config.macromodulations.list(lq)
|
||||
|
||||
if args.json:
|
||||
print(utils.json_formatter(macromodulations))
|
||||
@ -800,9 +984,34 @@ def do_config_macromodulation_delete(sc, args):
|
||||
sc.config.macromodulations.delete(args.macromodulation_name)
|
||||
|
||||
|
||||
@cliutils.arg("--notificationway_name", help="New name of the notificationway")
|
||||
@cliutils.arg("--host_notification_period")
|
||||
@cliutils.arg("--service_notification_period")
|
||||
@cliutils.arg("--host_notification_options", nargs='+')
|
||||
@cliutils.arg("--service_notification_options", nargs='+')
|
||||
@cliutils.arg("--host_notification_commands", nargs='+')
|
||||
@cliutils.arg("--service_notification_commands", nargs='+')
|
||||
@cliutils.arg("--min_business_impact")
|
||||
@cliutils.arg("--live_query", help="Live query")
|
||||
@cliutils.arg("--page_size", help="Number of returned data")
|
||||
@cliutils.arg("--page", help="Page number")
|
||||
def do_config_notificationway_list(sc, args):
|
||||
"""List all config notificationways."""
|
||||
notificationways = sc.config.notificationways.list()
|
||||
arg_names = ['notificationway_name',
|
||||
'host_notification_period',
|
||||
'service_notification_period',
|
||||
'host_notification_options',
|
||||
'service_notification_options',
|
||||
'service_notification_commands',
|
||||
'host_notification_commands',
|
||||
'min_business_impact',
|
||||
'live_query',
|
||||
'page_size',
|
||||
'page'
|
||||
]
|
||||
arg_dict = _dict_from_args(args, arg_names)
|
||||
lq = utils.create_query(**arg_dict)
|
||||
notificationways = sc.config.notificationways.list(lq)
|
||||
|
||||
if args.json:
|
||||
print(utils.json_formatter(notificationways))
|
||||
@ -913,9 +1122,24 @@ def do_config_notificationway_delete(sc, args):
|
||||
sc.config.notificationways.delete(args.notificationway_name)
|
||||
|
||||
|
||||
@cliutils.arg("--realm_name", help="New name of the realm")
|
||||
@cliutils.arg("--realm_members", nargs='+')
|
||||
@cliutils.arg("--default")
|
||||
@cliutils.arg("--live_query", help="Live query")
|
||||
@cliutils.arg("--page_size", help="Number of returned data")
|
||||
@cliutils.arg("--page", help="Page number")
|
||||
def do_config_realm_list(sc, args):
|
||||
"""List all config realms."""
|
||||
realms = sc.config.realms.list()
|
||||
arg_names = ['realm_name',
|
||||
'realm_members',
|
||||
'default',
|
||||
'live_query',
|
||||
'page_size',
|
||||
'page'
|
||||
]
|
||||
arg_dict = _dict_from_args(args, arg_names)
|
||||
lq = utils.create_query(**arg_dict)
|
||||
realms = sc.config.realms.list(lq)
|
||||
|
||||
if args.json:
|
||||
print(utils.json_formatter(realms))
|
||||
@ -984,9 +1208,32 @@ def do_config_realm_delete(sc, args):
|
||||
sc.config.realms.delete(args.realm_name)
|
||||
|
||||
|
||||
@cliutils.arg("--servicegroup_name", help="New name of the service group")
|
||||
@cliutils.arg("--members")
|
||||
@cliutils.arg("--alias")
|
||||
@cliutils.arg("--servicegroup_members")
|
||||
@cliutils.arg("--notes")
|
||||
@cliutils.arg("--notes_url")
|
||||
@cliutils.arg("--action_url")
|
||||
@cliutils.arg("--live_query", help="Live query")
|
||||
@cliutils.arg("--page_size", help="Number of returned data")
|
||||
@cliutils.arg("--page", help="Page number")
|
||||
def do_config_servicegroup_list(sc, args):
|
||||
"""List all config service groups."""
|
||||
servicegroups = sc.config.servicegroups.list()
|
||||
arg_names = ['servicegroup_name',
|
||||
'members',
|
||||
'alias',
|
||||
'servicegroup_members',
|
||||
'notes',
|
||||
'notes_url',
|
||||
'action_url',
|
||||
'live_query',
|
||||
'page_size',
|
||||
'page'
|
||||
]
|
||||
arg_dict = _dict_from_args(args, arg_names)
|
||||
lq = utils.create_query(**arg_dict)
|
||||
servicegroups = sc.config.servicegroups.list(lq)
|
||||
|
||||
if args.json:
|
||||
print(utils.json_formatter(servicegroups))
|
||||
@ -1084,9 +1331,48 @@ def do_config_servicegroup_delete(sc, args):
|
||||
sc.config.servicegroups.delete(args.servicegroup_name)
|
||||
|
||||
|
||||
@cliutils.arg("--host_name")
|
||||
@cliutils.arg("--service_description")
|
||||
@cliutils.arg("--check_command")
|
||||
@cliutils.arg("--max_check_attempts")
|
||||
@cliutils.arg("--check_interval")
|
||||
@cliutils.arg("--retry_interval")
|
||||
@cliutils.arg("--check_period")
|
||||
@cliutils.arg("--notification_interval")
|
||||
@cliutils.arg("--notification_period")
|
||||
@cliutils.arg("--contacts")
|
||||
@cliutils.arg("--contact_groups")
|
||||
@cliutils.arg("--passive_checks_enabled")
|
||||
@cliutils.arg("--use")
|
||||
@cliutils.arg("--name")
|
||||
@cliutils.arg("--register")
|
||||
@cliutils.arg("--live_query", help="Live query")
|
||||
@cliutils.arg("--page_size", help="Number of returned data")
|
||||
@cliutils.arg("--page", help="Page number")
|
||||
def do_config_service_list(sc, args):
|
||||
"""List all config services."""
|
||||
services = sc.config.services.list()
|
||||
arg_names = ['host_name',
|
||||
'service_description',
|
||||
'check_command',
|
||||
'max_check_attempts',
|
||||
'check_interval',
|
||||
'retry_interval',
|
||||
'check_period',
|
||||
'notification_interval',
|
||||
'notification_period',
|
||||
'contacts',
|
||||
'contact_groups',
|
||||
'passive_checks_enabled',
|
||||
'use',
|
||||
'name',
|
||||
'register',
|
||||
'live_query',
|
||||
'page_size',
|
||||
'page'
|
||||
]
|
||||
arg_dict = _dict_from_args(args, arg_names)
|
||||
lq = utils.create_query(**arg_dict)
|
||||
services = sc.config.services.list(lq)
|
||||
|
||||
if args.json:
|
||||
print(utils.json_formatter(services))
|
||||
@ -1151,9 +1437,26 @@ def do_config_service_delete(sc, args):
|
||||
args.service_description)
|
||||
|
||||
|
||||
@cliutils.arg("--timeperiod_name", help="New name of the timeperiod")
|
||||
@cliutils.arg("--exclude")
|
||||
@cliutils.arg("--periods", nargs='+')
|
||||
@cliutils.arg("--alias")
|
||||
@cliutils.arg("--live_query", help="Live query")
|
||||
@cliutils.arg("--page_size", help="Number of returned data")
|
||||
@cliutils.arg("--page", help="Page number")
|
||||
def do_config_timeperiod_list(sc, args):
|
||||
"""List all config timeperiods."""
|
||||
timeperiods = sc.config.timeperiods.list()
|
||||
arg_names = ['timeperiod_name',
|
||||
'exclude',
|
||||
'periods',
|
||||
'alias',
|
||||
'live_query',
|
||||
'page_size',
|
||||
'page'
|
||||
]
|
||||
arg_dict = _dict_from_args(args, arg_names)
|
||||
lq = utils.create_query(**arg_dict)
|
||||
timeperiods = sc.config.timeperiods.list(lq)
|
||||
|
||||
if args.json:
|
||||
print(utils.json_formatter(timeperiods))
|
||||
@ -1230,17 +1533,42 @@ def do_config_reload(sc, args):
|
||||
print(sc.config.reload_config()['message'])
|
||||
|
||||
|
||||
@cliutils.arg("--host_name", help="Host Name")
|
||||
@cliutils.arg("--address", help="address")
|
||||
@cliutils.arg("--state", help="state")
|
||||
@cliutils.arg("--last_check", help="Last check")
|
||||
@cliutils.arg("--last_state_change", help="Last state change")
|
||||
@cliutils.arg("--long_output", help="Long output")
|
||||
@cliutils.arg("--services", help="Services")
|
||||
@cliutils.arg("--childs", help="childs")
|
||||
@cliutils.arg("--parents", help="Parents")
|
||||
@cliutils.arg("--description", help="description")
|
||||
@cliutils.arg("--acknowledge", help="Acknowledge")
|
||||
@cliutils.arg("--plugin_output", help="Plugin output")
|
||||
@cliutils.arg("--live_query", help="Live query")
|
||||
@cliutils.arg("--page_size", help="Number of returned data")
|
||||
@cliutils.arg("--page", help="Page number")
|
||||
def do_status_host_list(sc, args):
|
||||
"""List all status hosts."""
|
||||
arg_names = ['live_query',
|
||||
arg_names = ['host_name',
|
||||
'address',
|
||||
'state',
|
||||
'last_check',
|
||||
'last_state_change',
|
||||
'long_output',
|
||||
'description',
|
||||
'acknowledged',
|
||||
'plugin_output',
|
||||
'services',
|
||||
'childs',
|
||||
'parents',
|
||||
'live_query',
|
||||
'page_size',
|
||||
'page'
|
||||
]
|
||||
arg = _dict_from_args(args, arg_names)
|
||||
services = sc.status.hosts.list(**arg)
|
||||
arg_dict = _dict_from_args(args, arg_names)
|
||||
lq = utils.create_query(**arg_dict)
|
||||
services = sc.status.hosts.list(lq)
|
||||
|
||||
if args.json:
|
||||
print(utils.json_formatter(services))
|
||||
@ -1279,18 +1607,29 @@ def do_status_host_show(sc, args):
|
||||
utils.print_item(host, hostProperties)
|
||||
|
||||
|
||||
@cliutils.arg("--host_name", help="Host name")
|
||||
@cliutils.arg("--service_description", help="Service description")
|
||||
@cliutils.arg("--state", help="State")
|
||||
@cliutils.arg("--last_check", help="Last check")
|
||||
@cliutils.arg("--plugin_output", help="Plugin Output")
|
||||
@cliutils.arg("--live_query", help="Live query")
|
||||
@cliutils.arg("--page_size", help="Number of returned data")
|
||||
@cliutils.arg("--page", help="Page number")
|
||||
def do_status_service_list(sc, args):
|
||||
"""List all status services."""
|
||||
|
||||
arg_names = ['live_query',
|
||||
arg_names = ['host_name',
|
||||
'service_description',
|
||||
'state',
|
||||
'last_check',
|
||||
'plugin_output',
|
||||
'live_query',
|
||||
'page_size',
|
||||
'page'
|
||||
]
|
||||
arg = _dict_from_args(args, arg_names)
|
||||
services = sc.status.services.list(**arg)
|
||||
arg_dict = _dict_from_args(args, arg_names)
|
||||
lq = utils.create_query(**arg_dict)
|
||||
services = sc.status.services.list(lq)
|
||||
|
||||
if args.json:
|
||||
print(utils.json_formatter(services))
|
||||
@ -1332,9 +1671,10 @@ def do_status_metrics_list(sc, args):
|
||||
'page_size',
|
||||
'page',
|
||||
]
|
||||
arg = _dict_from_args(args, arg_names)
|
||||
arg_dict = _dict_from_args(args, arg_names)
|
||||
lq = utils.create_query(**arg_dict)
|
||||
metrics = sc.status.hosts.metrics.list(lq)
|
||||
|
||||
metrics = sc.status.hosts.metrics.list(**arg)
|
||||
if args.json:
|
||||
print(utils.json_formatter(metrics))
|
||||
else:
|
||||
@ -1423,8 +1763,9 @@ def do_status_events_list(sc, args):
|
||||
'page_size',
|
||||
'page',
|
||||
'live_query']
|
||||
arg = _dict_from_args(args, arg_names)
|
||||
events = sc.status.events.list(**arg)
|
||||
arg_dict = _dict_from_args(args, arg_names)
|
||||
lq = utils.create_query(**arg_dict)
|
||||
events = sc.status.events.list(lq)
|
||||
|
||||
if args.json:
|
||||
print(utils.json_formatter(events))
|
||||
|
@ -13,34 +13,14 @@
|
||||
# under the License.
|
||||
|
||||
from surveilclient.common import surveil_manager
|
||||
from surveilclient.common import utils
|
||||
|
||||
|
||||
class EventsManager(surveil_manager.SurveilManager):
|
||||
base_url = '/status/events'
|
||||
|
||||
def list(self, host_name=None, service_description=None, event_type=None,
|
||||
start_time=None, end_time=None, live_query=None,
|
||||
page_size=None, page=None):
|
||||
def list(self, query=None):
|
||||
"""List events."""
|
||||
|
||||
filters = {
|
||||
'is': {
|
||||
'host_name': host_name,
|
||||
'service_description': service_description,
|
||||
'event_type': event_type
|
||||
}
|
||||
}
|
||||
|
||||
query = utils.create_query(
|
||||
query=live_query,
|
||||
filters=filters,
|
||||
start_time=start_time,
|
||||
end_time=end_time,
|
||||
page_size=page_size,
|
||||
page=page
|
||||
)
|
||||
|
||||
query = query or {}
|
||||
resp, body = self.http_client.json_request(
|
||||
EventsManager.base_url, 'POST', body=query
|
||||
)
|
||||
|
@ -13,7 +13,6 @@
|
||||
# under the License.
|
||||
|
||||
from surveilclient.common import surveil_manager
|
||||
from surveilclient.common import utils
|
||||
from surveilclient.v2_0.status.metrics import metrics
|
||||
|
||||
|
||||
@ -24,14 +23,9 @@ class HostsManager(surveil_manager.SurveilManager):
|
||||
super(HostsManager, self).__init__(http_client)
|
||||
self.metrics = metrics.MetricsManager(self.http_client)
|
||||
|
||||
def list(self, live_query=None, page_size=None, page=None):
|
||||
def list(self, query=None):
|
||||
"""Get a list of hosts."""
|
||||
|
||||
query = utils.create_query(
|
||||
query=live_query,
|
||||
page_size=page_size,
|
||||
page=page
|
||||
)
|
||||
query = query or {}
|
||||
resp, body = self.http_client.json_request(
|
||||
HostsManager.base_url, 'POST', body=query
|
||||
)
|
||||
|
@ -13,7 +13,6 @@
|
||||
# under the License.
|
||||
|
||||
from surveilclient.common import surveil_manager
|
||||
from surveilclient.common import utils
|
||||
|
||||
|
||||
class MetricsManager(surveil_manager.SurveilManager):
|
||||
@ -30,17 +29,9 @@ class MetricsManager(surveil_manager.SurveilManager):
|
||||
return body
|
||||
|
||||
def list(self, host_name, metric_name, service_description=None,
|
||||
live_query=None, start_time=None, end_time=None,
|
||||
page_size=None, page=None):
|
||||
query=None):
|
||||
"""Get a list of metrics name."""
|
||||
query = utils.create_query(
|
||||
query=live_query,
|
||||
start_time=start_time,
|
||||
end_time=end_time,
|
||||
page_size=page_size,
|
||||
page=page
|
||||
)
|
||||
|
||||
query = query or {}
|
||||
resp, body = self.http_client.json_request(
|
||||
self._create_url(host_name, service_description, metric_name),
|
||||
'POST', body=query)
|
||||
|
@ -13,19 +13,14 @@
|
||||
# under the License.
|
||||
|
||||
from surveilclient.common import surveil_manager
|
||||
from surveilclient.common import utils
|
||||
|
||||
|
||||
class ServicesManager(surveil_manager.SurveilManager):
|
||||
base_url = '/status/services'
|
||||
|
||||
def list(self, live_query=None, page_size=None, page=None):
|
||||
def list(self, query=None):
|
||||
"""Get a list of services."""
|
||||
query = utils.create_query(
|
||||
query=live_query,
|
||||
page_size=page_size,
|
||||
page=page
|
||||
)
|
||||
query = query or {}
|
||||
resp, body = self.http_client.json_request(
|
||||
ServicesManager.base_url, 'POST', body=query
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user