Here are the examples of the python api cmk.gui.livestatus_utils.commands.lowlevel.send_command taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
13 Examples
0
Source : acknowledgments.py
with GNU General Public License v2.0
from tribe29
with GNU General Public License v2.0
from tribe29
def acknowledge_service_problem(
connection,
host_name: str,
service_description: str,
sticky: bool = False,
notify: bool = False,
persistent: bool = False,
user: str = "",
comment: str = "",
):
"""Acknowledge the current problem for the given service.
When acknowledging a problem, furhter notifications for the service are disabled, as
long as the service doesn't change state. At state change, notifications are re-enabled.
Args:
connection:
A livestatus connection object.
host_name:
The host-name for which this acknowledgement is for.
service_description:
The service description of the service, whose problems shall be acknowledged.
sticky:
If set, only a state-change of the service to an OK state will discard the
acknowledgement. Otherwise it will be discarded on any state-change. Defaults to False.
notify:
If set, notifications will be sent out to the configured contacts. Defaults to False.
persistent:
If set, the comment will persist a restart. Defaults to False.
user:
comment:
If set, this comment will be stored alongside the acknowledgement.
Examples:
>>> from cmk.gui.livestatus_utils.testing import simple_expect
>>> cmd = "COMMAND [...] ACKNOWLEDGE_SVC_PROBLEM;example.com;drain;1;0;0;;"
>>> with simple_expect() as live:
... _ = live.expect_query("GET hosts\\nColumns: name\\nFilter: name = example.com")
... _ = live.expect_query(cmd, match_type="ellipsis")
... acknowledge_service_problem(live, 'example.com', 'drain')
"""
site_id = _query_site(connection, host_name)
acknowledgement = 2 if sticky else 1 # 1: normal, 2: sticky
return send_command(
connection,
"ACKNOWLEDGE_SVC_PROBLEM",
[
host_name,
service_description,
acknowledgement,
int(notify),
int(persistent),
user,
comment,
],
site_id=site_id,
)
def acknowledge_servicegroup_problem(
0
Source : acknowledgments.py
with GNU General Public License v2.0
from tribe29
with GNU General Public License v2.0
from tribe29
def acknowledge_servicegroup_problem(
connection,
servicegroup_name: str,
sticky: bool = False,
notify: bool = False,
persistent: bool = False,
user: str = "",
comment: str = "",
):
"""Acknowledge the problems of the current services of the service group
When acknowledging a problem, further notifications for the respective services are disabled, as
long as a specific service doesn't change state. At state change, notifications are re-enabled.
Args:
connection:
A livestatus connection object.
servicegroup_name:
The host-name for which this acknowledgement is for.
sticky:
If set, only a state-change of the service to an OK state will discard the
acknowledgement. Otherwise it will be discarded on any state-change. Defaults to False.
notify:
If set, notifications will be sent out to the configured contacts. Defaults to False.
persistent:
If set, the comment will persist a restart. Defaults to False.
user:
comment:
If set, this comment will be stored alongside the acknowledgement.
Raises:
ValueError:
When the service group could not be found.
"""
with detailed_connection(connection) as conn:
group_entries = Query(
[tables.Servicegroups.members],
tables.Servicegroups.name.equals(servicegroup_name),
).fetchall(conn)
acknowledgement = 2 if sticky else 1 # 1: normal, 2: sticky
for entry in group_entries:
site_id = entry["site"]
for host_name, service_description in entry["members"]:
send_command(
connection,
"ACKNOWLEDGE_SVC_PROBLEM",
[
host_name,
service_description,
acknowledgement,
int(notify),
int(persistent),
user,
comment,
],
site_id=site_id,
)
def acknowledge_host_problem(
0
Source : acknowledgments.py
with GNU General Public License v2.0
from tribe29
with GNU General Public License v2.0
from tribe29
def acknowledge_host_problem(
connection,
host_name,
sticky: bool = False,
notify: bool = False,
persistent: bool = False,
user: str = "",
comment: str = "",
):
"""Acknowledge the current problem for the given host.
When acknowledging a problem, notifications for the host are disabled, as long as the
host doesn't change state. At state change, notifications are re-enabled.
Args:
connection:
A livestatus connection object.
host_name:
The host-name for which this acknowledgement is for.
sticky:
If set, only a state-change of the host to an UP state will discard the acknowledgement.
Otherwise it will be discarded on any state-change. Defaults to False.
notify:
If set, notifications will be sent out to the configured contacts. Defaults to False.
persistent:
If set, the comment will persist a restart. Defaults to False.
user:
comment:
If set, this comment will be stored alongside the acknowledgement.
Examples:
>>> from cmk.gui.livestatus_utils.testing import simple_expect
>>> cmd = "COMMAND [...] ACKNOWLEDGE_HOST_PROBLEM;example.com;1;0;0;;"
>>> with simple_expect() as live:
... _ = live.expect_query("GET hosts\\nColumns: name\\nFilter: name = example.com")
... _ = live.expect_query(cmd, match_type="ellipsis")
... acknowledge_host_problem(live, 'example.com')
"""
acknowledgement = 2 if sticky else 1 # 1: normal, 2: sticky
with detailed_connection(connection) as conn:
site_id = Query([Hosts.name], Hosts.name.equals(host_name)).first_value(conn)
return send_command(
connection,
"ACKNOWLEDGE_HOST_PROBLEM",
[
host_name,
acknowledgement,
int(notify),
int(persistent),
user,
comment,
],
site_id=site_id,
)
def acknowledge_hostgroup_problem(
0
Source : acknowledgments.py
with GNU General Public License v2.0
from tribe29
with GNU General Public License v2.0
from tribe29
def acknowledge_hostgroup_problem(
connection,
hostgroup_name: str,
sticky: bool = False,
notify: bool = False,
persistent: bool = False,
user: str = "",
comment: str = "",
):
"""Acknowledge the problems of the current hosts of the host group
When acknowledging a problem, further notifications for the respective services are disabled, as
long as a specific service doesn't change state. At state change, notifications are re-enabled.
Args:
connection:
A livestatus connection object.
hostgroup_name:
The name of the host group.
sticky:
If set, only a state-change of the service to an OK state will discard the
acknowledgement. Otherwise it will be discarded on any state-change. Defaults to False.
notify:
If set, notifications will be sent out to the configured contacts. Defaults to False.
persistent:
If set, the comment will persist a restart. Defaults to False.
user:
comment:
If set, this comment will be stored alongside the acknowledgement.
Raises:
ValueError:
when the host group in question doesn't exist.
"""
with detailed_connection(connection) as conn:
group_entries = Query(
[tables.Hostgroups.members], tables.Hostgroups.name.equals(hostgroup_name)
).fetchall(conn)
acknowledgement = 2 if sticky else 1 # 1: normal, 2: sticky
for entry in group_entries:
site_id = entry["site"]
for host_name in entry["members"]:
send_command(
connection,
"ACKNOWLEDGE_HOST_PROBLEM",
[
host_name,
acknowledgement,
int(notify),
int(persistent),
user,
comment,
],
site_id=site_id,
)
def _query_site(connection, host_name: str) -> SiteId:
0
Source : comment.py
with GNU General Public License v2.0
from tribe29
with GNU General Public License v2.0
from tribe29
def add_host_comment(
connection,
host_name: str,
comment: str,
persistent: bool = False,
user: str = "",
):
"""Add a comment for a particular host.
Args:
connection:
A livestatus connection object
host_name:
The host-name for which the comment is for
comment:
The comment which will be stored for the host
persistent:
If set, the comment will persist across program restarts until it is delete manually.
If not set, the comment will be deleted the next time the Core is restarted.
user:
Examples:
>>> from cmk.gui.livestatus_utils.testing import simple_expect
>>> cmd = "COMMAND [...] ADD_HOST_COMMENT;example.com;0;;test"
>>> with simple_expect(cmd, match_type="ellipsis") as live:
... add_host_comment(live, 'example.com', 'test')
"""
return send_command(
connection,
"ADD_HOST_COMMENT",
[host_name, int(persistent), user, comment],
)
def del_host_comment(connection, comment_id: int):
0
Source : comment.py
with GNU General Public License v2.0
from tribe29
with GNU General Public License v2.0
from tribe29
def del_host_comment(connection, comment_id: int):
"""Delete a host comment
Args:
connection:
A livestatus connection object
comment_id:
The id of the host comment
Examples:
>>> from cmk.gui.livestatus_utils.testing import simple_expect
>>> cmd = "COMMAND [...] DEL_HOST_COMMENT;1234"
>>> with simple_expect(cmd, match_type="ellipsis") as live:
... del_host_comment(live, 1234)
"""
return send_command(
connection,
"DEL_HOST_COMMENT",
[comment_id],
)
def add_service_comment(
0
Source : comment.py
with GNU General Public License v2.0
from tribe29
with GNU General Public License v2.0
from tribe29
def add_service_comment(
connection,
host_name: str,
service_description: str,
comment: str,
persistent: bool = False,
user: str = "",
):
"""Add service comment
Args:
connection:
A livestatus connection object
host_name:
The host-name where the service is located
service_description:
The service description for which the comment is for
comment:
The comment which will be stored for the service
persistent:
If set, the comment will persist across program restarts until it is delete manually.
If not set, the comment will be deleted the next time the Core is restarted.
user:
Examples:
>>> from cmk.gui.livestatus_utils.testing import simple_expect
>>> cmd = "COMMAND [...] ADD_SVC_COMMENT;example.com;CPU Load;0;;test"
>>> with simple_expect(cmd, match_type="ellipsis") as live:
... add_service_comment(live, 'example.com', 'CPU Load', 'test')
"""
return send_command(
connection,
"ADD_SVC_COMMENT",
[host_name, service_description, int(persistent), user, comment],
)
def del_service_comment(connection, comment_id: int):
0
Source : comment.py
with GNU General Public License v2.0
from tribe29
with GNU General Public License v2.0
from tribe29
def del_service_comment(connection, comment_id: int):
"""Delete a service comment
Args:
connection:
A livestatus connection object
comment_id:
The id of the service comment
Examples:
>>> from cmk.gui.livestatus_utils.testing import simple_expect
>>> cmd = "COMMAND [...] DEL_SVC_COMMENT;1234"
>>> with simple_expect(cmd, match_type="ellipsis") as live:
... del_service_comment(live, 1234)
"""
return send_command(
connection,
"DEL_SVC_COMMENT",
[comment_id],
)
0
Source : downtimes.py
with GNU General Public License v2.0
from tribe29
with GNU General Public License v2.0
from tribe29
def del_host_downtime(
connection,
downtime_id: int,
site_id: SiteId,
):
"""Delete a host downtime.
Args:
connection:
A livestatus connection object.
downtime_id:
The downtime-id.
site_id:
Id of site where command should be executed.
Examples:
>>> from cmk.gui.livestatus_utils.testing import simple_expect
>>> with simple_expect("COMMAND [...] DEL_HOST_DOWNTIME;1", match_type="ellipsis") as live:
... del_host_downtime(live, 1, "")
"""
return send_command(connection, "DEL_HOST_DOWNTIME", [downtime_id], site_id)
def del_service_downtime(
0
Source : downtimes.py
with GNU General Public License v2.0
from tribe29
with GNU General Public License v2.0
from tribe29
def del_service_downtime(
connection,
downtime_id: int,
site_id: SiteId,
):
"""Delete a service downtime.
Args:
connection:
A livestatus connection object.
downtime_id:
The downtime-id.
site_id:
Id of site where command should be executed.
Examples:
>>> from cmk.gui.livestatus_utils.testing import simple_expect
>>> with simple_expect("COMMAND [...] DEL_SVC_DOWNTIME;1", match_type="ellipsis") as live:
... del_service_downtime(live, 1, "")
"""
return send_command(connection, "DEL_SVC_DOWNTIME", [downtime_id], site_id)
def delete_downtime_with_query(connection, query):
0
Source : downtimes.py
with GNU General Public License v2.0
from tribe29
with GNU General Public License v2.0
from tribe29
def _schedule_downtime(
sites,
command: LivestatusCommand,
site_id,
host_or_group: str,
service_description: Optional[str],
start_time: dt.datetime,
end_time: dt.datetime,
recur: RecurMode = "fixed",
trigger_id: int = 0,
duration: int = 0,
user_id: str = "",
comment: str = "",
):
"""Unified low level function
See:
* schedule_host_downtime
* schedule_service_downtime
"""
# TODO: provide reference documents for recurring magic numbers
recur_mode = _recur_mode(recur, duration)
if command == "SCHEDULE_HOST_DOWNTIME":
params = [host_or_group]
elif command == "SCHEDULE_SVC_DOWNTIME":
if not service_description:
raise ValueError("Service description necessary.")
params = [host_or_group, service_description]
else:
raise ValueError(f"Unsupported command: {command}")
return send_command(
sites,
command,
[
*params,
to_timestamp(start_time),
to_timestamp(end_time),
recur_mode,
trigger_id,
duration,
user_id,
comment.replace("\n", ""),
],
site_id,
)
def _recur_mode(recur: RecurMode, duration: int) -> int:
0
Source : force_schedule.py
with GNU General Public License v2.0
from tribe29
with GNU General Public License v2.0
from tribe29
def force_schedule_host_check(connection, host_name: str, check_time: dt.datetime):
"""Schedule a forced active check of a particular host
Args:
connection:
A livestatus connection object
host_name:
The name of the host where the forced check should be performed on
check_time:
The time at which this forced check should be performed
Examples:
>>> import pytz
>>> _check_time = dt.datetime(1970, 1, 1, tzinfo=pytz.timezone("UTC"))
>>> from cmk.gui.livestatus_utils.testing import simple_expect
>>> cmd = "COMMAND [...] SCHEDULE_FORCED_HOST_CHECK;example.com;0"
>>> with simple_expect(cmd, match_type="ellipsis") as live:
... force_schedule_host_check(live, 'example.com', _check_time)
"""
return send_command(
connection, "SCHEDULE_FORCED_HOST_CHECK", [host_name, to_timestamp(check_time)]
)
def force_schedule_service_check(
0
Source : force_schedule.py
with GNU General Public License v2.0
from tribe29
with GNU General Public License v2.0
from tribe29
def force_schedule_service_check(
connection, host_name: str, service_description: str, check_time: dt.datetime
):
"""Schedule a forced active check of a particular service
Args:
connection:
A livestatus connection object
host_name:
The name of the host where the service is
service_description:
The service description for which the forced check should be performed on
check_time:
The time at which this forced check should be performed
Examples:
>>> import pytz
>>> _check_time = dt.datetime(1970, 1, 1, tzinfo=pytz.timezone("UTC"))
>>> from cmk.gui.livestatus_utils.testing import simple_expect
>>> cmd = "COMMAND [...] SCHEDULE_FORCED_SVC_CHECK;example.com;CPU Load;0"
>>> with simple_expect(cmd, match_type="ellipsis") as live:
... force_schedule_service_check(live,'example.com', 'CPU Load', _check_time)
"""
return send_command(
connection,
"SCHEDULE_FORCED_SVC_CHECK",
[host_name, service_description, to_timestamp(check_time)],
)