Implemented passive checks
Change-Id: Id46d15f11293062a79818f7974144445d64d9e19
This commit is contained in:
parent
440272aec4
commit
8fae1a236f
@ -66,4 +66,4 @@ class TestServices(clienttest.ClientTest):
|
||||
self.assertEqual(
|
||||
body,
|
||||
"body"
|
||||
)
|
||||
)
|
||||
|
@ -12,6 +12,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
|
||||
import httpretty
|
||||
|
||||
from surveilclient.tests.v2_0 import clienttest
|
||||
@ -46,3 +48,20 @@ class TestHosts(clienttest.ClientTest):
|
||||
host,
|
||||
{"host_name": "host1"}
|
||||
)
|
||||
|
||||
@httpretty.activate
|
||||
def test_submit_host_check_result(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.POST, "http://localhost:8080/v2/status/hosts/localhost"
|
||||
"/results",
|
||||
body=''
|
||||
)
|
||||
|
||||
self.client.status.hosts.submit_check_result(
|
||||
"localhost", output="someoutput"
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
json.loads(httpretty.last_request().body.decode()),
|
||||
{"output": u"someoutput"}
|
||||
)
|
@ -12,6 +12,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
|
||||
import httpretty
|
||||
|
||||
from surveilclient.tests.v2_0 import clienttest
|
||||
@ -31,4 +33,24 @@ class TestServices(clienttest.ClientTest):
|
||||
self.assertEqual(
|
||||
services,
|
||||
[{"service_name": "service1"}]
|
||||
)
|
||||
)
|
||||
|
||||
@httpretty.activate
|
||||
def test_submit_service_check_result(self):
|
||||
httpretty.register_uri(
|
||||
httpretty.POST,
|
||||
"http://localhost:8080/v2/status/hosts/localhost"
|
||||
"/services/testservice/results",
|
||||
body=''
|
||||
)
|
||||
|
||||
self.client.status.services.submit_check_result(
|
||||
"localhost",
|
||||
'testservice',
|
||||
output="someoutputt"
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
json.loads(httpretty.last_request().body.decode()),
|
||||
{"output": u"someoutputt"}
|
||||
)
|
||||
|
@ -75,7 +75,7 @@ def do_config_host_update(sc, args):
|
||||
if "custom_fields" in host:
|
||||
host["custom_fields"] = json.loads(host["custom_fields"])
|
||||
|
||||
sc.config.hosts.update(**host)
|
||||
sc.config.hosts.update(args.host_name, **host)
|
||||
|
||||
|
||||
@cliutils.arg("--host_name", help="Name of the host")
|
||||
@ -166,6 +166,7 @@ def do_config_service_list(sc, args):
|
||||
@cliutils.arg("--notification_period")
|
||||
@cliutils.arg("--contacts")
|
||||
@cliutils.arg("--contact_groups")
|
||||
@cliutils.arg("--passive_checks_enabled")
|
||||
def do_config_service_create(sc, args):
|
||||
"""Create a config service."""
|
||||
arg_names = ['host_name',
|
||||
@ -179,6 +180,7 @@ def do_config_service_create(sc, args):
|
||||
'notification_period',
|
||||
'contacts',
|
||||
'contact_groups',
|
||||
'passive_checks_enabled',
|
||||
'use']
|
||||
service = _dict_from_args(args, arg_names)
|
||||
sc.config.services.create(**service)
|
||||
@ -428,6 +430,27 @@ def do_status_metrics_show(sc, args):
|
||||
utils.print_item(metric, metricProperties)
|
||||
|
||||
|
||||
@cliutils.arg("--host_name", help="Name of the host")
|
||||
@cliutils.arg("--service_description", help="Service description")
|
||||
@cliutils.arg("--output", help="The output of the plugin")
|
||||
@cliutils.arg("--return_code", help="The return code of the plugin")
|
||||
def do_status_submit_check_result(sc, args):
|
||||
"""Submit a check result."""
|
||||
if args.service_description:
|
||||
sc.status.services.submit_check_result(
|
||||
args.host_name,
|
||||
args.service_description,
|
||||
output=args.output,
|
||||
return_code=int(args.return_code),
|
||||
)
|
||||
else:
|
||||
sc.status.hosts.submit_check_result(
|
||||
args.host_name,
|
||||
output=args.output,
|
||||
return_code=int(args.return_code),
|
||||
)
|
||||
|
||||
|
||||
@cliutils.arg("--host_name", help="Name of the host")
|
||||
@cliutils.arg("--service_description", help="Service description")
|
||||
@cliutils.arg("--time_stamp")
|
||||
|
@ -36,3 +36,11 @@ class HostsManager(surveil_manager.SurveilManager):
|
||||
HostsManager.base_url + "/" + host_name, 'GET'
|
||||
)
|
||||
return body
|
||||
|
||||
def submit_check_result(self, host_name, **kwargs):
|
||||
"""Submit a check result."""
|
||||
resp, body = self.http_client.json_request(
|
||||
HostsManager.base_url + '/' + host_name + '/results', 'POST',
|
||||
body=kwargs
|
||||
)
|
||||
return body
|
||||
|
@ -24,3 +24,13 @@ class ServicesManager(surveil_manager.SurveilManager):
|
||||
ServicesManager.base_url, 'POST', body=live_query
|
||||
)
|
||||
return body
|
||||
|
||||
def submit_check_result(self, host_name, service_description, **kwargs):
|
||||
"""Submit a check result."""
|
||||
resp, body = self.http_client.json_request(
|
||||
'/status/hosts/%s/services/%s/results' % (host_name,
|
||||
service_description),
|
||||
'POST',
|
||||
body=kwargs
|
||||
)
|
||||
return body
|
||||
|
Loading…
x
Reference in New Issue
Block a user