Implemented passive checks
Change-Id: Id46d15f11293062a79818f7974144445d64d9e19
This commit is contained in:
@@ -12,6 +12,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
import httpretty
|
import httpretty
|
||||||
|
|
||||||
from surveilclient.tests.v2_0 import clienttest
|
from surveilclient.tests.v2_0 import clienttest
|
||||||
@@ -46,3 +48,20 @@ class TestHosts(clienttest.ClientTest):
|
|||||||
host,
|
host,
|
||||||
{"host_name": "host1"}
|
{"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
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
import httpretty
|
import httpretty
|
||||||
|
|
||||||
from surveilclient.tests.v2_0 import clienttest
|
from surveilclient.tests.v2_0 import clienttest
|
||||||
@@ -32,3 +34,23 @@ class TestServices(clienttest.ClientTest):
|
|||||||
services,
|
services,
|
||||||
[{"service_name": "service1"}]
|
[{"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:
|
if "custom_fields" in host:
|
||||||
host["custom_fields"] = json.loads(host["custom_fields"])
|
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")
|
@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("--notification_period")
|
||||||
@cliutils.arg("--contacts")
|
@cliutils.arg("--contacts")
|
||||||
@cliutils.arg("--contact_groups")
|
@cliutils.arg("--contact_groups")
|
||||||
|
@cliutils.arg("--passive_checks_enabled")
|
||||||
def do_config_service_create(sc, args):
|
def do_config_service_create(sc, args):
|
||||||
"""Create a config service."""
|
"""Create a config service."""
|
||||||
arg_names = ['host_name',
|
arg_names = ['host_name',
|
||||||
@@ -179,6 +180,7 @@ def do_config_service_create(sc, args):
|
|||||||
'notification_period',
|
'notification_period',
|
||||||
'contacts',
|
'contacts',
|
||||||
'contact_groups',
|
'contact_groups',
|
||||||
|
'passive_checks_enabled',
|
||||||
'use']
|
'use']
|
||||||
service = _dict_from_args(args, arg_names)
|
service = _dict_from_args(args, arg_names)
|
||||||
sc.config.services.create(**service)
|
sc.config.services.create(**service)
|
||||||
@@ -428,6 +430,27 @@ def do_status_metrics_show(sc, args):
|
|||||||
utils.print_item(metric, metricProperties)
|
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("--host_name", help="Name of the host")
|
||||||
@cliutils.arg("--service_description", help="Service description")
|
@cliutils.arg("--service_description", help="Service description")
|
||||||
@cliutils.arg("--time_stamp")
|
@cliutils.arg("--time_stamp")
|
||||||
|
|||||||
@@ -36,3 +36,11 @@ class HostsManager(surveil_manager.SurveilManager):
|
|||||||
HostsManager.base_url + "/" + host_name, 'GET'
|
HostsManager.base_url + "/" + host_name, 'GET'
|
||||||
)
|
)
|
||||||
return body
|
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
|
ServicesManager.base_url, 'POST', body=live_query
|
||||||
)
|
)
|
||||||
return body
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user