Submodules
pretiac (__init__.py)
pretiac is a Python module to interact with the Icinga 2 RESTful API.
- pretiac.set_default_client(config_file: str | Path | None = None, api_endpoint_host: str | None = None, api_endpoint_port: int | None = None, http_basic_username: str | None = None, http_basic_password: str | None = None, client_private_key: str | None = None, client_certificate: str | None = None, ca_certificate: str | None = None, suppress_exception: bool | None = None) Client[source]
Set and configure the default client.
- Parameters:
config_file – The path of the configuration file to load.
api_endpoint_host – The domain or the IP address of the API endpoint, e. g.
icinga.example.com,localhostor127.0.0.1.api_endpoint_port – The TCP port of the API endpoint, for example
5665.http_basic_username – The name of the API user used in the HTTP basic authentification, e. g.
apiuser.http_basic_password – The password of the API user used in the HTTP basic authentification, e. g.
password.client_private_key – The file path of the client’s private RSA key, for example
/etc/pretiac/api-client.key.pem.client_certificate – The file path of the client’s certificate, for example
/etc/pretiac/api-client.cert.pem.ca_certificate – The file path of the Icinga CA (Certification Authority), for example
/var/lib/icinga2/certs/ca.crt.suppress_exception – If set to
True, no exceptions are thrown.
- pretiac.get_default_client() Client[source]
Get the default client.
This function intentionally has no input parameters. Use the function
set_default_client()to set a new configured client.However, this function loads a client configured by configuration files in the following order (if the function
set_default_client()was not called before):The file path in the environment variable
PRETIAC_CONFIG_FILE.The configuration file in the home folder
~/.pretiac.yml.The configuration file at
/etc/pretiac/config.yml.
--- api_endpoint_host: localhost api_endpoint_port: 5665 client_private_key: /etc/pretiac/api-client.key.pem client_certificate: /etc/pretiac/api-client.cert.pem ca_certificate: /etc/pretiac/ca.crt new_host_defaults: templates: [passive-host] new_service_defaults: templates: [passive-service] attrs: check_interval: monthly
pretiac.client
A high level client with typed return values.
- class pretiac.client.CheckResponse(*, code: int, status: str)[source]
Bases:
BaseModel- model_config
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pretiac.client.CheckError(*, error: int, status: str)[source]
Bases:
BaseModel- model_config
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pretiac.client.Client(config: Config | None = None, config_file: str | Path | Literal[False] | None = None, api_endpoint_host: str | None = None, api_endpoint_port: int | None = None, http_basic_username: str | None = None, http_basic_password: str | None = None, client_private_key: str | None = None, client_certificate: str | None = None, ca_certificate: str | None = None, suppress_exception: bool | None = None, new_host_defaults: ObjectConfig | None = None, new_service_defaults: ObjectConfig | None = None)[source]
Bases:
objectThe high level client with typed output.
It is a wrapper around the
RawClient.- get_check_commands() Sequence[CheckCommand][source]
- get_dependencys() Sequence[Dependency][source]
- create_host(name: str, display_name: str | None = None, templates: Sequence[str] | None = None, attrs: dict[str, Any] | None = None, object_config: ObjectConfig | None = None, suppress_exception: bool | None = None) Host | None[source]
Create a new host. If no host configuration is specified, the template
generic-hostis assigned.- Parameters:
name – The name of the host.
display_name – A short description of the host.
templates – Import existing configuration templates for this object type. Note: These templates must either be statically configured or provided in config packages.
attrs – Set specific object attributes for this object type.
object_config – Bundle of all configurations required to create a host.
suppress_exception – If this parameter is set to
True, no exceptions are thrown.
The method call
client.create_host(name='framework')
creates for example a configuration file in the location
/var/lib/icinga2/api/packages/_api/33d433c5-2c2f-4159-84fc-41395ddcd04d/conf.d/hosts/framework.confwith the content:object Host "framework" { import "generic-host" version = 1725393956.244954 zone = "master" }
- get_host(name: str) Host | None[source]
Get a single host.
- Parameters:
name – The name of the host.
- create_service(name: str, host: str, display_name: str | None = None, templates: Sequence[str] | None = None, attrs: dict[str, Any] | None = None, object_config: ObjectConfig | None = None, suppress_exception: bool | None = None) Service | None[source]
Create a new service. If no service configuration is specified, the dummy check command is assigned.
- Parameters:
name – The name of the service.
host – The name of the host.
display_name – A short description of the service.
templates – Import existing configuration templates for this object type. Note: These templates must either be statically configured or provided in config packages.
attrs – Set specific object attributes for this object type.
object_config – Bundle of all configurations required to create a service.
suppress_exception – If this parameter is set to
True, no exceptions are thrown.
client.create_service(name='procs_zombie', host='framework', display_name='Zombie processes')
Creates a configuration file like
/var/lib/icinga2/api/packages/_api/33d433c5-2c2f-4159-84fc-41395ddcd04d/conf.d/services/framework!procs_zombie.confthis one:object Service "procs_zombie" { check_command = "dummy" display_name = "Zombie processes" host_name = "framework" version = 1725393956.973319 zone = "master" }
- get_service(name: str | None = None, host: str | None = None, service: str | None = None) Service[source]
- Parameters:
name – The full name of the service, for example
host!service.host – The name of the host.
service – The name of the service.
- delete_service(name: str | None = None, host: str | None = None, service: str | None = None) None[source]
- Parameters:
name – The full name of the service, for example
host!service.host – The name of the host.
service – The name of the service.
- send_service_check_result(service: str, host: str | None = None, exit_status: HostState | ServiceState | Literal[0, 1, 2, 3] | int | None = ServiceState.OK, plugin_output: str | None = None, performance_data: Sequence[str] | str | None = None, check_command: Sequence[str] | str | None = None, check_source: str | None = None, execution_start: float | None = None, execution_end: float | None = None, ttl: int | None = None, create: bool = True, display_name: str | None = None, new_host_defaults: ObjectConfig | None = None, new_service_defaults: ObjectConfig | None = None) CheckResponse | CheckError[source]
Send a check result for a service and create the host or the service if necessary.
- Parameters:
service – The name of the service.
host – The name of the host.
exit_status – For services:
0=OK,1=WARNING,2=CRITICAL,3=UNKNOWN, for hosts:0=UP,1=DOWN.plugin_output – One or more lines of the plugin main output. Does not contain the performance data.
performance_data – The performance data.
check_command – The first entry should be the check commands path, then one entry for each command line option followed by an entry for each of its argument. Alternativly a single string can be used.
check_source – Usually the name of the
command_endpoint.execution_start – The timestamp where a script/process started its execution.
execution_end – The timestamp where a script/process ended its execution. This timestamp is used in features to determine e.g. the metric timestamp.
ttl – Time-to-live duration in seconds for this check result. The next expected check result is
now + ttlwhere freshness checks are executed.create – Whether non-existent services and hosts should be created.
display_name – A short description of the service, if it needs to be created.
new_host_defaults – If a new host needs to be created, use this defaults.
new_service_defaults – If a new service needs to be created, use this defaults.
- get_time_periods() Sequence[TimePeriod][source]
- subscribe_events(types: Sequence[Literal['CheckResult', 'StateChange', 'Notification', 'AcknowledgementSet', 'AcknowledgementCleared', 'CommentAdded', 'CommentRemoved', 'DowntimeAdded', 'DowntimeRemoved', 'DowntimeStarted', 'DowntimeTriggered', 'ObjectCreated', 'ObjectDeleted', 'ObjectModified']], queue: str, filter: str | None = None, filter_vars: dict[str, Any] | None = None)[source]
- get_status() Sequence[StatusMessage][source]
- list_config_packages() Sequence[ConfigPackage][source]
- list_config_stage_files(package_name: str, stage_name: str) ConfigPackageStageFiles[source]
- Parameters:
package_name – Package names with the
_prefix are reserved for internal packages and must not be used. You can recognize_api,_etcand_clusterwhen querying specific objects and packages.stage_name – The stage name, for example
7e7861c8-8008-4e8d-9910-2a0bb26921bd.
- list_all_config_stage_files() list[ConfigPackageStageFiles][source]
- delete_config(package_name: str, stage_name: str | None)[source]
Delete a configuration package or a configuration stage entirely.
If the parameter
stage_nameis not specified, the entire configuration package is deleted. If the parameterstage_nameis provided, only the specified configuration stage is deleted.- Parameters:
package_name – Package names with the
_prefix are reserved for internal packages and must not be used. You can recognize_api,_etcand_clusterwhen querying specific objects and packages.stage_name – The stage name, for example
7e7861c8-8008-4e8d-9910-2a0bb26921bd.
pretiac.config
- class pretiac.config.ObjectConfig(templates: Sequence[str] | None = None, attrs: Payload | None = None)[source]
Bases:
objectBundles all configuration required to create an object.
- class pretiac.config.Config(config_file: Path | None = None, api_endpoint_host: str | None = None, api_endpoint_port: int | None = None, http_basic_username: str | None = None, http_basic_password: str | None = None, client_private_key: str | None = None, client_certificate: str | None = None, ca_certificate: str | None = None, suppress_exception: bool | None = None, new_host_defaults: ObjectConfig | None = None, new_service_defaults: ObjectConfig | None = None)[source]
Bases:
object- See:
- api_endpoint_host: str | None
The domain or the IP address of the API endpoint, e. g.
icinga.example.com,localhostor127.0.0.1.
- http_basic_username: str | None
The name of the API user used in the HTTP basic authentification, e. g.
apiuser.object ApiUser "apiuser" { ... }
- http_basic_password: str | None
The password of the API user used in the HTTP basic authentification, e. g.
password.object ApiUser "apiuser" { password = "password" }
- See:
- client_private_key: str | None
The file path of the client’s private RSA key, for example
/etc/pretiac/api-client.key.pem.The RSA private key is created with this command:
icinga2 pki new-cert \ --cn api-client \ --key api-client.key.pem \ --csr api-client.csr.pem
- client_certificate: str | None
The file path of the client certificate.
The certificate is created with this command:
icinga2 pki sign-csr \ --csr api-client.csr.pem \ --cert api-client.cert.pem
- ca_certificate: str | None
The file path of the Icinga CA (Certification Authority).
The CA certificate is located at
/var/lib/icinga2/certs/ca.crt. This command copies the certificate to the local host.scp icinga-master:/var/lib/icinga2/certs/ca.crt .
- new_host_defaults: ObjectConfig | None
If a new host needs to be created, use this defaults.
- new_service_defaults: ObjectConfig | None
If a new service needs to be created, use this defaults.
- pretiac.config.load_config_file(config_file: str | Path | None = None) Config[source]
Load the configuration file in YAML format.
The file path of the loaded configuration file is determined in this order:
The parameter
config_fileof this function.The file path in the environment variable
PRETIAC_CONFIG_FILE.The configuration file in the home folder
~/.pretiac.yml.The configuration file at
/etc/pretiac/config.yml.
- Parameters:
config_file – The path of the configuration file to load.
- pretiac.config.load_config(config: Config | None = None, config_file: str | Path | Literal[False] | None = None, api_endpoint_host: str | None = None, api_endpoint_port: int | None = None, http_basic_username: str | None = None, http_basic_password: str | None = None, client_private_key: str | None = None, client_certificate: str | None = None, ca_certificate: str | None = None, suppress_exception: bool | None = None, new_host_defaults: ObjectConfig | None = None, new_service_defaults: ObjectConfig | None = None) Config[source]
- Parameters:
config – A configuration object that has already been populated.
config_file – The path of the configuration file to load. If this value is set to false no configuration file will be loaded.
api_endpoint_host – The domain or the IP address of the API endpoint, e. g.
icinga.example.com,localhostor127.0.0.1.api_endpoint_port – The TCP port of the API endpoint, for example
5665.http_basic_username – The name of the API user used in the HTTP basic authentification, e. g.
apiuser.http_basic_password – The password of the API user used in the HTTP basic authentification, e. g.
password.client_private_key – The file path of the client’s private RSA key, for example
/etc/pretiac/api-client.key.pem.client_certificate – The file path of the client’s certificate, for example
/etc/pretiac/api-client.cert.pem.ca_certificate – The file path of the Icinga CA (Certification Authority), for example
/var/lib/icinga2/certs/ca.crt.suppress_exception – If set to
True, no exceptions are thrown.new_host_defaults – If a new host needs to be created, use this defaults.
new_service_defaults – If a new service needs to be created, use this defaults.
pretiac.exceptions
Icinga 2 API client exceptions
- exception pretiac.exceptions.PretiacException[source]
Bases:
ExceptionIcinga 2 API exception class
- exception pretiac.exceptions.PretiacRequestException(message: str, response: Payload)[source]
Bases:
PretiacExceptionIcinga 2 API Request exception class
- response: Payload
pretiac.object_types
All available config object types.
Listed in the same order as in this Markdown document.
- pretiac.object_types.OptionalStr
An empty string is set to None by the Pydantic validator.
alias of
Annotated[str|None,BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)]
- pretiac.object_types.MonitoringObjectName
see doc/09-object-types.md object-types-monitoring
alias of
Literal[‘ApiUser’, ‘CheckCommand’, ‘Dependency’, ‘Endpoint’, ‘EventCommand’, ‘Host’, ‘HostGroup’, ‘Notification’, ‘NotificationCommand’, ‘ScheduledDowntime’, ‘Service’, ‘ServiceGroup’, ‘TimePeriod’, ‘User’, ‘UserGroup’, ‘Zone’]
- pretiac.object_types.RuntimeObjectName
see [doc/09-object-types.md runtime-objects-](https://github.com/Icinga/icinga2/b
alias of
Literal[‘Comment’, ‘Downtime’]
- pretiac.object_types.FeatureObjectName
see doc/09-object-types.md features-
alias of
Literal[‘ApiListener’, ‘CheckerComponent’, ‘CompatLogger’, ‘ElasticsearchWriter’, ‘ExternalCommandListener’, ‘FileLogger’, ‘GelfWriter’, ‘GraphiteWriter’, ‘IcingaApplication’, ‘IcingaDB’, ‘IdoMySqlConnection’, ‘IdoPgsqlConnection’, ‘InfluxdbWriter’, ‘Influxdb2Writer’, ‘JournaldLogger’, ‘LiveStatusListener’, ‘NotificationComponent’, ‘OpenTsdbWriter’, ‘PerfdataWriter’, ‘SyslogLogger’, ‘WindowsEventLogLogger’]
- pretiac.object_types.normalize_to_plural_snake_object_type_name(object_type_name: str) str[source]
for example:
ApiUsertoapi_users- Returns:
A pluralized object type name in the snake case.
- pretiac.object_types.pluralize_to_lower_object_type_name(object_type_name: Literal['ApiUser', 'CheckCommand', 'Dependency', 'Endpoint', 'EventCommand', 'Host', 'HostGroup', 'Notification', 'NotificationCommand', 'ScheduledDowntime', 'Service', 'ServiceGroup', 'TimePeriod', 'User', 'UserGroup', 'Zone', 'Comment', 'Downtime', 'ApiListener', 'CheckerComponent', 'CompatLogger', 'ElasticsearchWriter', 'ExternalCommandListener', 'FileLogger', 'GelfWriter', 'GraphiteWriter', 'IcingaApplication', 'IcingaDB', 'IdoMySqlConnection', 'IdoPgsqlConnection', 'InfluxdbWriter', 'Influxdb2Writer', 'JournaldLogger', 'LiveStatusListener', 'NotificationComponent', 'OpenTsdbWriter', 'PerfdataWriter', 'SyslogLogger', 'WindowsEventLogLogger']) str[source]
for example:
ApiUsertoapiusers
- pretiac.object_types.RequestMethod
-
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
alias of
Literal[‘GET’, ‘OPTIONS’, ‘HEAD’, ‘POST’, ‘PUT’, ‘PATCH’, ‘DELETE’]
- class pretiac.object_types.SourceLocation(path: str, first_line: int, first_column: int, last_line: int, last_column: int)[source]
Bases:
object
- class pretiac.object_types.HAMode(*values)[source]
Bases:
EnumHA= High-Availability- HARunOnce
- HARunEverywhere
- class pretiac.object_types.StateType(*values)[source]
Bases:
Enumsee: lib/icinga/checkresult.ti L38-L43
- StateTypeSoft
- StateTypeHard
- pretiac.object_types.Timestamp
for example 1699475880.364077
- pretiac.object_types.Value
A type that can hold an arbitrary value.
- class pretiac.object_types.ServiceState(*values)[source]
Bases:
Enum0=OK, 1=WARNING, 2=CRITICAL, 3=UNKNOWN
- OK
- WARNING
- CRITICAL
- UNKNOWN
- pretiac.object_types.get_service_state(state: HostState | ServiceState | Literal[0, 1, 2, 3] | int | Any) ServiceState[source]
- class pretiac.object_types.CheckResult(exit_status: int, output: str, performance_data: list[str] | None, check_source: str, scheduling_source: str, state: ServiceState, previous_hard_state: ServiceState | int, command: list[str] | str | None, execution_start: float, execution_end: float, schedule_start: float, schedule_end: float, active: bool, vars_before: dict[str, Any] | None, vars_after: dict[str, Any], ttl: int)[source]
Bases:
objectThe attributes are as listed in the offical Icinga2 documentation.
- type
- state: ServiceState
The current state (0 = OK, 1 = WARNING, 2 = CRITICAL, 3 = UNKNOWN).
- previous_hard_state: ServiceState | int
Sometimes
99?
- command: list[str] | str | None
Array of command with shell-escaped arguments or command line string.
- class pretiac.object_types.ConfigObject(name: str | None = None, type: str | None = None, zone: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, package: str | None = None, templates: Sequence[str] | None = None, source_location: SourceLocation | None = None, active: bool | None = None, paused: bool | None = None, ha_mode: HAMode | None = None, original_attributes: dict[str, Any] | None = None, version: float | None = None)[source]
Bases:
object- zone: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)]
- source_location: SourceLocation | None
- class pretiac.object_types.CustomVarObject(name: str | None = None, type: str | None = None, zone: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, package: str | None = None, templates: Sequence[str] | None = None, source_location: SourceLocation | None = None, active: bool | None = None, paused: bool | None = None, ha_mode: HAMode | None = None, original_attributes: dict[str, Any] | None = None, version: float | None = None, vars: dict[str, Any] | None = None)[source]
Bases:
ConfigObject
- class pretiac.object_types.Checkable(name: str | None = None, type: str | None = None, zone: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, package: str | None = None, templates: Sequence[str] | None = None, source_location: SourceLocation | None = None, active: bool | None = None, paused: bool | None = None, ha_mode: HAMode | None = None, original_attributes: dict[str, Any] | None = None, version: float | None = None, vars: dict[str, Any] | None = None, check_command: str | None = None, max_check_attempts: int | None = None, check_period: str | None = None, check_timeout: int | float | str | bool | Any | None = None, check_interval: float | None = None, retry_interval: float | None = None, event_command: str | None = None, volatile: bool | None = None, enable_active_checks: bool | None = None, enable_passive_checks: bool | None = None, enable_event_handler: bool | None = None, enable_notifications: bool | None = None, enable_flapping: bool | None = None, enable_perfdata: bool | None = None, flapping_ignore_states: Sequence[str] | None = None, flapping_threshold: float | None = None, flapping_threshold_low: float | None = None, flapping_threshold_high: float | None = None, notes: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, notes_url: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, action_url: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, icon_image: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, icon_image_alt: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, next_check: float | None = None, check_attempt: int | None = None, state_type: StateType | None = None, last_state_type: StateType | None = None, last_reachable: bool | None = None, last_check_result: CheckResult | None = None, last_state_change: float | None = None, last_hard_state_change: float | None = None, last_state_unreachable: float | None = None, previous_state_change: float | None = None, severity: int | None = None, problem: bool | None = None, handled: bool | None = None, next_update: float | None = None, force_next_check: bool | None = None, acknowledgement: int | None = None, acknowledgement_expiry: float | None = None, acknowledgement_last_change: float | None = None, force_next_notification: bool | None = None, last_check: float | None = None, downtime_depth: int | None = None, flapping_current: float | None = None, flapping_last_change: float | None = None, flapping: bool | None = None, command_endpoint: str | None = None, executions: Dictionary | None = None)[source]
Bases:
CustomVarObject- max_check_attempts: int | None
The float of times a service is re-checked before changing into a hard state. Defaults to 3.
- check_period: str | None
The name of a time period which determines when this service should be checked. Not set by default (effectively 24x7).
- check_timeout: int | float | str | bool | Any | None
Check command timeout in seconds. Overrides the CheckCommand’s timeout attribute.
- check_interval: float | None
The check interval (in seconds). This interval is used for checks when the service is in a HARD state. Defaults to 5m.
- retry_interval: float | None
This interval is used for checks when the service is in a SOFT state. Defaults to 1m. Note: This does not affect the scheduling after a passive check result.
- notes: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)]
Optional. Notes for the checkable.
- notes_url: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)]
Optional. URL for notes for the checkable (for example, in notification commands).
- action_url: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)]
Optional. URL for actions for the checkable (for example, an external graphing tool).
- icon_image: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)]
Optional. Icon image for the checkable. Used by external interfaces only.
- icon_image_alt: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)]
Optional. Icon image description for the checkable. Used by external interface only.
- last_check_result: CheckResult | None
- executions: Dictionary | None
- class pretiac.object_types.ApiUser(name: str | None = None, type: str | None = None, zone: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, package: str | None = None, templates: Sequence[str] | None = None, source_location: SourceLocation | None = None, active: bool | None = None, paused: bool | None = None, ha_mode: HAMode | None = None, original_attributes: dict[str, Any] | None = None, version: float | None = None, password: str | None = None, client_cn: str | None = None, permissions: Sequence[str] | None = None)[source]
Bases:
ConfigObjectApiUser objects are used for authentication against the Icinga 2 API.
object ApiUser "root" { password = "mysecretapipassword" permissions = [ "*" ] }
https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#apiuser :see: lib/remote/apiuser.ti :see: doc/09-object-types.md L41-L63
- class pretiac.object_types.Function(type: str, name: str, side_effect_free: bool, deprecated: bool, arguments: Sequence[str])[source]
Bases:
object
- class pretiac.object_types.CheckCommandArguments(key: str | None = None, value: str | Function | Any | None = None, description: str | None = None, required: bool | None = None, skip_key: bool | None = None, repeat_key: bool | None = None, set_if: str | Function | None = None, order: float | None = None, separator: str | None = None)[source]
Bases:
objectCommand arguments can be defined as key-value-pairs in the arguments dictionary. Best practice is to assign a dictionary as value which provides additional details such as the description next to the value.
Example
arguments = { "--parameter" = { description = "..." value = "..." } }
- See:
- See:
- See:
- class pretiac.object_types.CheckCommand(name: str | None = None, type: str | None = None, zone: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, package: str | None = None, templates: Sequence[str] | None = None, source_location: SourceLocation | None = None, active: bool | None = None, paused: bool | None = None, ha_mode: HAMode | None = None, original_attributes: dict[str, Any] | None = None, version: float | None = None, vars: dict[str, Any] | None = None, timeout: int | None = None, execute: str | Function | None = None, command: Sequence[str] | dict[str, Any] | None = None, arguments: dict[str, CheckCommandArguments | str | Sequence[str] | dict[str, Any]] | str | None = None, env: Any | None = None)[source]
Bases:
CustomVarObjectA check command definition. Additional default command custom variables can be defined here.
Example
object CheckCommand "http" { command = [ PluginDir + "/check_http" ] arguments = { "-H" = "$http_vhost$" "-I" = "$http_address$" "-u" = "$http_uri$" "-p" = "$http_port$" "-S" = { set_if = "$http_ssl$" } "--sni" = { set_if = "$http_sni$" } "-a" = { value = "$http_auth_pair$" description = "Username:password on sites with basic authentication" } "--no-body" = { set_if = "$http_ignore_body$" } "-r" = "$http_expect_body_regex$" "-w" = "$http_warn_time$" "-c" = "$http_critical_time$" "-e" = "$http_expect$" } vars.http_address = "$address$" vars.http_ssl = false vars.http_sni = false }
https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#checkcommand :see: doc/09-object-types.md L65-L114 :see: lib/icinga/command.ti
- command: Sequence[str] | dict[str, Any] | None
Required. The command. This can either be an array of individual command arguments. Alternatively a string can be specified in which case the shell interpreter (usually /bin/sh) takes care of parsing the command. When using the “arguments” attribute this must be an array. Can be specified as function for advanced implementations.
- arguments: dict[str, CheckCommandArguments | str | Sequence[str] | dict[str, Any]] | str | None
Optional. A dictionary of command arguments.
- class pretiac.object_types.Dependency(name: str | None = None, type: str | None = None, zone: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, package: str | None = None, templates: Sequence[str] | None = None, source_location: SourceLocation | None = None, active: bool | None = None, paused: bool | None = None, ha_mode: HAMode | None = None, original_attributes: dict[str, Any] | None = None, version: float | None = None, vars: dict[str, Any] | None = None, parent_host_name: str | None = None, parent_service_name: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, child_host_name: str | None = None, child_service_name: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, redundancy_group: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, disable_checks: bool | None = None, disable_notifications: bool | None = None, ignore_soft_states: bool | None = None, period: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, states: Sequence[str] | None = None)[source]
Bases:
CustomVarObjectDependency objects are used to specify dependencies between hosts and services. Dependencies can be defined as Host-to-Host, Service-to-Service, Service-to-Host, or Host-to-Service relations.
Service-to-Service Example:
object Dependency "webserver-internet" { parent_host_name = "internet" parent_service_name = "ping4" child_host_name = "webserver" child_service_name = "ping4" states = [ OK, Warning ] disable_checks = true }
Host-to-Host Example:
object Dependency "webserver-internet" { parent_host_name = "internet" child_host_name = "webserver" states = [ Up ] disable_checks = true }
https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#dependency :see: doc/09-object-types.md L153-L258 https://github.com/Icinga/icinga2/blob/c0b047b1aab6de3c5e51fdeb63d3bf4236f7fa6d/lib/icinga/dependency.ti#L21-L99
- parent_service_name: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)]
Optional. The parent service. If omitted, this dependency object is treated as host dependency.
- child_service_name: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)]
Optional. The child service. If omitted, this dependency object is treated as host dependency.
- redundancy_group: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)]
Optional. Puts the dependency into a group of mutually redundant ones.
- disable_checks: bool | None
Optional. Whether to disable checks (i.e., don’t schedule active checks and drop passive results) when this dependency fails. Defaults to false.
- disable_notifications: bool | None
Optional. Whether to disable notifications when this dependency fails. Defaults to true.
- ignore_soft_states: bool | None
Optional. Whether to ignore soft states for the reachability calculation. Defaults to true.
- class pretiac.object_types.Endpoint(name: str | None = None, type: str | None = None, zone: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, package: str | None = None, templates: Sequence[str] | None = None, source_location: SourceLocation | None = None, active: bool | None = None, paused: bool | None = None, ha_mode: HAMode | None = None, original_attributes: dict[str, Any] | None = None, version: float | None = None, host: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, port: int | None = None, log_duration: str | int | None = None, local_log_position: float | None = None, remote_log_position: float | None = None, icinga_version: int | None = None, capabilities: int | None = None, connecting: bool | None = None, syncing: bool | None = None, connected: bool | None = None, last_message_sent: float | None = None, last_message_received: float | None = None, messages_sent_per_second: float | None = None, messages_received_per_second: float | None = None, bytes_sent_per_second: float | None = None, bytes_received_per_second: float | None = None, messages_received_per_type: dict[Any, Any] | None = None, seconds_processing_messages: float | None = None)[source]
Bases:
ConfigObjectEndpoint objects are used to specify connection information for remote Icinga 2 instances.
Example
object Endpoint "icinga2-agent1.localdomain" { host = "192.168.56.111" port = 5665 log_duration = 1d }
Example (disable replay log):
object Endpoint "icinga2-agent1.localdomain" { host = "192.168.5.111" port = 5665 log_duration = 0 }
https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#endpoint :see: doc/09-object-types.md L260-L293 https://github.com/Icinga/icinga2/blob/333534096ebc251de08cecd2f688bc690253902c/lib/remote/endpoint.ti#L12-L66
- host: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)]
The hostname/IP address of the remote Icinga 2 instance.
- log_duration: str | int | None
Optional. Duration for keeping replay logs on connection loss. Defaults to 1d (86400 seconds). Attribute is specified in seconds. If log_duration is set to 0, replaying logs is disabled. You could also specify the value in human readable format like 10m for 10 minutes or 1h for one hour.
- class pretiac.object_types.EventCommand[source]
Bases:
objectAn event command definition.
object EventCommand "restart-httpd-event" { command = "/opt/bin/restart-httpd.sh" }
https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#eventcommand :see: doc/09-object-types.md L295-L320
- class pretiac.object_types.Host(name: str | None = None, type: str | None = None, zone: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, package: str | None = None, templates: Sequence[str] | None = None, source_location: SourceLocation | None = None, active: bool | None = None, paused: bool | None = None, ha_mode: HAMode | None = None, original_attributes: dict[str, Any] | None = None, version: float | None = None, vars: dict[str, Any] | None = None, check_command: str | None = None, max_check_attempts: int | None = None, check_period: str | None = None, check_timeout: int | float | str | bool | Any | None = None, check_interval: float | None = None, retry_interval: float | None = None, event_command: str | None = None, volatile: bool | None = None, enable_active_checks: bool | None = None, enable_passive_checks: bool | None = None, enable_event_handler: bool | None = None, enable_notifications: bool | None = None, enable_flapping: bool | None = None, enable_perfdata: bool | None = None, flapping_ignore_states: Sequence[str] | None = None, flapping_threshold: float | None = None, flapping_threshold_low: float | None = None, flapping_threshold_high: float | None = None, notes: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, notes_url: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, action_url: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, icon_image: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, icon_image_alt: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, next_check: float | None = None, check_attempt: int | None = None, state_type: StateType | None = None, last_state_type: StateType | None = None, last_reachable: bool | None = None, last_check_result: CheckResult | None = None, last_state_change: float | None = None, last_hard_state_change: float | None = None, last_state_unreachable: float | None = None, previous_state_change: float | None = None, severity: int | None = None, problem: bool | None = None, handled: bool | None = None, next_update: float | None = None, force_next_check: bool | None = None, acknowledgement: int | None = None, acknowledgement_expiry: float | None = None, acknowledgement_last_change: float | None = None, force_next_notification: bool | None = None, last_check: float | None = None, downtime_depth: int | None = None, flapping_current: float | None = None, flapping_last_change: float | None = None, flapping: bool | None = None, command_endpoint: str | None = None, executions: Dictionary | None = None, groups: Sequence[str] | None = None, display_name: str | None = None, address: str | None = None, address6: str | None = None, state: HostState | None = None, last_state: HostState | None = None, last_hard_state: HostState | None = None, last_state_up: float | None = None, last_state_down: float | None = None)[source]
Bases:
CheckableA host.
object Host "icinga2-agent1.localdomain" { display_name = "Linux Client 1" address = "192.168.56.111" address6 = "2a00:1450:4001:815::2003" groups = [ "linux-servers" ] check_command = "hostalive" }
- display_name: str | None
A short description of the host (e.g. displayed by external interfaces instead of the name if set).
- address6: str | None
The host’s IPv6 address. Available as command runtime macro
$address6$if set.
- class pretiac.object_types.HostGroup[source]
Bases:
objectA group of hosts.
object HostGroup "linux-servers" { display_name = "Linux Servers" assign where host.vars.os == "Linux" }
https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#hostgroup :see: doc/09-object-types.md L417-L440
- class pretiac.object_types.Notification[source]
Bases:
objectNotification objects are used to specify how users should be notified in case of host and service state changes and other events.
Example:
object Notification "localhost-ping-notification" { host_name = "localhost" service_name = "ping4" command = "mail-notification" users = [ "user1", "user2" ] // reference to User objects types = [ Problem, Recovery ] states = [ Critical, Warning, OK ] }
https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#notification :see: doc/09-object-types.md L444-L527
- class pretiac.object_types.NotificationCommand[source]
Bases:
objectA notification command definition.
object NotificationCommand "mail-service-notification" { command = [ ConfigDir + "/scripts/mail-service-notification.sh" ] arguments += { "-4" = { required = true value = "$notification_address$" } "-6" = "$notification_address6$" "-b" = "$notification_author$" "-c" = "$notification_comment$" "-d" = { required = true value = "$notification_date$" } "-e" = { required = true value = "$notification_servicename$" } "-f" = { value = "$notification_from$" description = "Set from address. Requires GNU mailutils (Debian/Ubuntu) or mailx (RHEL/SUSE)" } "-i" = "$notification_icingaweb2url$" "-l" = { required = true value = "$notification_hostname$" } "-n" = { required = true value = "$notification_hostdisplayname$" } "-o" = { required = true value = "$notification_serviceoutput$" } "-r" = { required = true value = "$notification_useremail$" } "-s" = { required = true value = "$notification_servicestate$" } "-t" = { required = true value = "$notification_type$" } "-u" = { required = true value = "$notification_servicedisplayname$" } "-v" = "$notification_logtosyslog$" } vars += { notification_address = "$address$" notification_address6 = "$address6$" notification_author = "$notification.author$" notification_comment = "$notification.comment$" notification_type = "$notification.type$" notification_date = "$icinga.long_date_time$" notification_hostname = "$host.name$" notification_hostdisplayname = "$host.display_name$" notification_servicename = "$service.name$" notification_serviceoutput = "$service.output$" notification_servicestate = "$service.state$" notification_useremail = "$user.email$" notification_servicedisplayname = "$service.display_name$" } }
https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#notificationcommand :see: doc/09-object-types.md L530-L622
- class pretiac.object_types.ScheduledDowntime[source]
Bases:
objectScheduledDowntime objects can be used to set up recurring downtimes for hosts/services.
Example:
object ScheduledDowntime "some-downtime" { host_name = "localhost" service_name = "ping4" author = "icingaadmin" comment = "Some comment" fixed = false duration = 30m ranges = { "sunday" = "02:00-03:00" } }
https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#scheduleddowntime :see: doc/09-object-types.md L624-L674
- class pretiac.object_types.Service(name: str | None = None, type: str | None = None, zone: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, package: str | None = None, templates: Sequence[str] | None = None, source_location: SourceLocation | None = None, active: bool | None = None, paused: bool | None = None, ha_mode: HAMode | None = None, original_attributes: dict[str, Any] | None = None, version: float | None = None, vars: dict[str, Any] | None = None, check_command: str | None = None, max_check_attempts: int | None = None, check_period: str | None = None, check_timeout: int | float | str | bool | Any | None = None, check_interval: float | None = None, retry_interval: float | None = None, event_command: str | None = None, volatile: bool | None = None, enable_active_checks: bool | None = None, enable_passive_checks: bool | None = None, enable_event_handler: bool | None = None, enable_notifications: bool | None = None, enable_flapping: bool | None = None, enable_perfdata: bool | None = None, flapping_ignore_states: Sequence[str] | None = None, flapping_threshold: float | None = None, flapping_threshold_low: float | None = None, flapping_threshold_high: float | None = None, notes: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, notes_url: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, action_url: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, icon_image: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, icon_image_alt: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, next_check: float | None = None, check_attempt: int | None = None, state_type: StateType | None = None, last_state_type: StateType | None = None, last_reachable: bool | None = None, last_check_result: CheckResult | None = None, last_state_change: float | None = None, last_hard_state_change: float | None = None, last_state_unreachable: float | None = None, previous_state_change: float | None = None, severity: int | None = None, problem: bool | None = None, handled: bool | None = None, next_update: float | None = None, force_next_check: bool | None = None, acknowledgement: int | None = None, acknowledgement_expiry: float | None = None, acknowledgement_last_change: float | None = None, force_next_notification: bool | None = None, last_check: float | None = None, downtime_depth: int | None = None, flapping_current: float | None = None, flapping_last_change: float | None = None, flapping: bool | None = None, command_endpoint: str | None = None, executions: Dictionary | None = None, groups: Sequence[str] | None = None, display_name: str | None = None, host_name: str | None = None, host: Host | None = None, state: ServiceState | None = None, last_state: ServiceState | None = None, last_hard_state: ServiceState | None = None, last_state_ok: float | None = None, last_state_warning: float | None = None, last_state_critical: float | None = None, last_state_unknown: float | None = None)[source]
Bases:
CheckableService objects describe network services and how they should be checked by Icinga 2.
Best Practice
Rather than creating a
Serviceobject for a specific host it is usually easier to just create aServicetemplate and use theapplykeyword to assign the service to a float of hosts. Check the apply chapter for details.Example:
object Service "uptime" { host_name = "localhost" display_name = "localhost Uptime" check_command = "snmp" vars.snmp_community = "public" vars.snmp_oid = "DISMAN-EVENT-MIB::sysUpTimeInstance" check_interval = 60s retry_interval = 15s groups = [ "all-services", "snmp" ] }
https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#service :see: lib/icinga/service.ti :see: doc/09-object-types.md L677-L781
- host_name: str | None
The host this service belongs to. There must be a Host object with that name.
- state: ServiceState | None
The current state (0 = OK, 1 = WARNING, 2 = CRITICAL, 3 = UNKNOWN).
- last_state: ServiceState | None
The previous state (0 = OK, 1 = WARNING, 2 = CRITICAL, 3 = UNKNOWN).
- last_hard_state: ServiceState | None
The last hard state (0 = OK, 1 = WARNING, 2 = CRITICAL, 3 = UNKNOWN).
- class pretiac.object_types.ServiceGroup[source]
Bases:
objectA group of services.
Example:
object ServiceGroup "snmp" { display_name = "SNMP services" }
https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#servicegroup :see: doc/09-object-types.md L784-L805
- class pretiac.object_types.TimePeriod(name: str | None = None, type: str | None = None, zone: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, package: str | None = None, templates: Sequence[str] | None = None, source_location: SourceLocation | None = None, active: bool | None = None, paused: bool | None = None, ha_mode: HAMode | None = None, original_attributes: dict[str, Any] | None = None, version: float | None = None, vars: dict[str, Any] | None = None, display_name: str | None = None, ranges: dict[str, str] | None = None, update: dict[str, Any] | None = None, prefer_includes: bool | None = None, excludes: Sequence[str] | None = None, includes: Sequence[str] | None = None, valid_begin: float | None = None, valid_end: float | None = None, segments: Sequence[TimePeriodSegment] | None = None, is_inside: bool | None = None)[source]
Bases:
CustomVarObjectTime periods can be used to specify when hosts/services should be checked or to limit when notifications should be sent out.
Examples:
object TimePeriod "nonworkhours" { display_name = "Icinga 2 TimePeriod for non working hours" ranges = { monday = "00:00-8:00,17:00-24:00" tuesday = "00:00-8:00,17:00-24:00" wednesday = "00:00-8:00,17:00-24:00" thursday = "00:00-8:00,17:00-24:00" friday = "00:00-8:00,16:00-24:00" saturday = "00:00-24:00" sunday = "00:00-24:00" } }
object TimePeriod "exampledays" { display_name = "Icinga 2 TimePeriod for random example days" ranges = { //We still believe in Santa, no peeking! //Applies every 25th of December every year "december 25" = "00:00-24:00" //Any point in time can be specified, //but you still have to use a range "2038-01-19" = "03:13-03:15" //Evey 3rd day from the second monday of February //to 8th of November "monday 2 february - november 8 / 3" = "00:00-24:00" } }Additional examples can be found here.
https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#timeperiod :see: doc/09-object-types.md L809-L869 :see: lib/icinga/timeperiod.ti L11-L39
- ranges: dict[str, str] | None
A dictionary containing information which days and durations apply to this timeperiod.
- segments: Sequence[TimePeriodSegment] | None
- class pretiac.object_types.User(name: str | None = None, type: str | None = None, zone: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, package: str | None = None, templates: Sequence[str] | None = None, source_location: SourceLocation | None = None, active: bool | None = None, paused: bool | None = None, ha_mode: HAMode | None = None, original_attributes: dict[str, Any] | None = None, version: float | None = None, vars: dict[str, Any] | None = None, display_name: str | None = None, groups: Sequence[str] | None = None, period: str | None = None, types: Sequence[str] | None = None, states: Sequence[str] | None = None, email: str | None = None, pager: str | None = None, enable_notifications: bool | None = None, last_notification: float | None = None)[source]
Bases:
CustomVarObjectA user.
Example:
object User "icingaadmin" { display_name = "Icinga 2 Admin" groups = [ "icingaadmins" ] email = "icinga@localhost" pager = "icingaadmin@localhost.localdomain" period = "24x7" states = [ OK, Warning, Critical, Unknown ] types = [ Problem, Recovery ] vars.additional_notes = "This is the Icinga 2 Admin account." }
Available notification state filters:
OK Warning Critical Unknown Up Down
Available notification type filters:
DowntimeStart DowntimeEnd DowntimeRemoved Custom Acknowledgement Problem Recovery FlappingStart FlappingEnd
https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#user :see: lib/icinga/user.ti :see: doc/09-object-types.md L872-L937
- period: str | None
The name of a time period which determines when a notification for this user should be triggered. Not set by default (effectively 24x7).
- types: Sequence[str] | None
A set of type filters when a notification for this user should be triggered. By default everything is matched.
- states: Sequence[str] | None
A set of state filters when a notification for this should be triggered. By default everything is matched.
- enable_notifications: bool | None
Whether notifications are enabled for this user. Defaults to true.
- class pretiac.object_types.UserGroup(name: str | None = None, type: str | None = None, zone: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, package: str | None = None, templates: Sequence[str] | None = None, source_location: SourceLocation | None = None, active: bool | None = None, paused: bool | None = None, ha_mode: HAMode | None = None, original_attributes: dict[str, Any] | None = None, version: float | None = None, vars: dict[str, Any] | None = None, display_name: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, groups: Sequence[str] | None = None)[source]
Bases:
CustomVarObjectA user group.
Example:
object UserGroup "icingaadmins" { display_name = "Icinga 2 Admin Group" }
https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#usergroup :see: doc/09-object-types.md L939-L960 https://github.com/Icinga/icinga2/blob/c0b047b1aab6de3c5e51fdeb63d3bf4236f7fa6d/lib/icinga/usergroup.ti#L10-L23
- class pretiac.object_types.Zone(name: str | None = None, type: str | None = None, zone: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, package: str | None = None, templates: Sequence[str] | None = None, source_location: SourceLocation | None = None, active: bool | None = None, paused: bool | None = None, ha_mode: HAMode | None = None, original_attributes: dict[str, Any] | None = None, version: float | None = None, endpoints: Sequence[str] | None = None, parent: Annotated[str | None, BeforeValidator(func=_empty_str_to_none, json_schema_input_type=PydanticUndefined)] = None, all_parents: Sequence[str] | None = None, is_global: bool | None = None)[source]
Bases:
ConfigObjectZone objects are used to specify which Icinga 2 instances are located in a zone.
Example:
object Zone "master" { endpoints = [ "icinga2-master1.localdomain", "icinga2-master2.localdomain" ] } object Zone "satellite" { endpoints = [ "icinga2-satellite1.localdomain" ] parent = "master" }
https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#zone :see: doc/09-object-types.md L963-L989 https://github.com/Icinga/icinga2/blob/c0b047b1aab6de3c5e51fdeb63d3bf4236f7fa6d/lib/remote/zone.ti#L10-L23
- class pretiac.object_types.Downtime(host_name: str | None = None, service_name: str | None = None, author: str | None = None, comment: str | None = None, start_time: float | None = None, end_time: float | None = None, duration: int | None = None, entry_time: float | None = None, fixed: bool | None = None, triggers: Sequence[str] | None = None)[source]
Bases:
objectDowntimes created at runtime are represented as objects. You can create downtimes with the schedule-downtime API action.
Example:
object Downtime "my-downtime" { host_name = "localhost" author = "icingaadmin" comment = "This is a downtime." start_time = 1505312869 end_time = 1505312924 }
- service_name: str | None
Optional. The short name of the service this downtime belongs to. If omitted, this downtime object is treated as host downtime.
- pretiac.object_types.EventStreamType
- See:
- See:
- See:
alias of
Literal[‘CheckResult’, ‘StateChange’, ‘Notification’, ‘AcknowledgementSet’, ‘AcknowledgementCleared’, ‘CommentAdded’, ‘CommentRemoved’, ‘DowntimeAdded’, ‘DowntimeRemoved’, ‘DowntimeStarted’, ‘DowntimeTriggered’, ‘ObjectCreated’, ‘ObjectDeleted’, ‘ObjectModified’]
- class pretiac.object_types.EventStreamTypeCheckResult(type: Literal['CheckResult'], timestamp: float, host: str, check_result: CheckResult, downtime_depth: float, acknowledgement: bool, service: str | None = None)[source]
Bases:
objecthttps://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-checkresult
- check_result: CheckResult
Serialized CheckResult value type.
- class pretiac.object_types.EventStreamTypeStateChange(type: Literal['StateChange'])[source]
Bases:
objecthttps://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-statechange
- class pretiac.object_types.EventStreamTypeNotification(type: Literal['Notification'])[source]
Bases:
objecthttps://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-notification
- class pretiac.object_types.EventStreamTypeFlapping(type: Literal['Flapping'])[source]
Bases:
objecthttps://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-flapping
- class pretiac.object_types.EventStreamTypeAcknowledgementSet(type: Literal['AcknowledgementSet'])[source]
Bases:
objecthttps://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-acknowledgementset
- class pretiac.object_types.EventStreamTypeAcknowledgementCleared(type: Literal['AcknowledgementCleared'])[source]
Bases:
objecthttps://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-acknowledgementcleared
- class pretiac.object_types.EventStreamTypeCommentAdded(timestamp: float, comment: Comment, type: Literal['CommentAdded'])[source]
Bases:
_EventStreamTypeCommenthttps://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-commentadded
- class pretiac.object_types.EventStreamTypeCommentRemoved(timestamp: float, comment: Comment, type: Literal['CommentRemoved'])[source]
Bases:
_EventStreamTypeCommenthttps://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-commentremoved
- class pretiac.object_types.EventStreamTypeDowntimeAdded(timestamp: float, downtime: Downtime, type: Literal['DowntimeAdded'])[source]
Bases:
_EventStreamTypeDowntimehttps://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-downtimeadded
- class pretiac.object_types.EventStreamTypeDowntimeRemoved(timestamp: float, downtime: Downtime, type: Literal['DowntimeRemoved'])[source]
Bases:
_EventStreamTypeDowntimehttps://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-downtimeremoved
- class pretiac.object_types.EventStreamTypeDowntimeStarted(timestamp: float, downtime: Downtime, type: Literal['DowntimeStarted'])[source]
Bases:
_EventStreamTypeDowntimehttps://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-downtimestarted
- class pretiac.object_types.EventStreamTypeDowntimeTriggered(timestamp: float, downtime: Downtime, type: Literal['DowntimeTriggered'])[source]
Bases:
_EventStreamTypeDowntimehttps://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-downtimetriggered
- class pretiac.object_types.PerfdataValue(label: str, value: float, counter: bool, unit: str, crit: int | float | str | bool | Any | None = None, warn: int | float | str | bool | Any | None = None, min: int | float | str | bool | Any | None = None, max: int | float | str | bool | Any | None = None)[source]
Bases:
objectlib/base/perfdatavalue.ti L8-L18 lib/base/perfdatavalue.hpp L17-L36
- class pretiac.object_types.StatusMessage(name: str, status: dict[str, Any], perfdata: Sequence[PerfdataValue] | None)[source]
Bases:
object- perfdata: Sequence[PerfdataValue] | None
- class pretiac.object_types.ConfigPackage(name: str, stages: Sequence[str], active_stage: str)[source]
Bases:
object
- class pretiac.object_types.ConfigFile(name: str, type: Literal['directory', 'file'])[source]
Bases:
object
- class pretiac.object_types.ConfigPackageStageFiles(package: str, stage: str, files: Sequence[ConfigFile])[source]
Bases:
object- files: Sequence[ConfigFile]
- class pretiac.object_types.TypeFieldAttributeInfo(config: bool, state: bool, required: bool, navigation: bool, no_user_modify: bool, no_user_view: bool, deprecated: bool)[source]
Bases:
object
- class pretiac.object_types.TypeFieldInfo(id: int, type: Literal['Array', 'Boolean', 'CheckResult', 'Dictionary', 'Function', 'Host', 'Namespace', 'Number', 'Object', 'Service', 'String', 'Timestamp', 'Type', 'uint_fast64_t', 'unsigned long', 'unsigned short', 'Value'], array_rank: int, attributes: TypeFieldAttributeInfo, ref_type: str | None = None, navigation_name: str | None = None)[source]
Bases:
object- type: Literal['Array', 'Boolean', 'CheckResult', 'Dictionary', 'Function', 'Host', 'Namespace', 'Number', 'Object', 'Service', 'String', 'Timestamp', 'Type', 'uint_fast64_t', 'unsigned long', 'unsigned short', 'Value']
- attributes: TypeFieldAttributeInfo
- class pretiac.object_types.TypeInfo(name: str, plural_name: str, abstract: bool, fields: dict[str, TypeFieldInfo], prototype_keys: Sequence[str], base: str | None = None)[source]
Bases:
object- fields: dict[str, TypeFieldInfo]
- class pretiac.object_types.Variable(name: str, type: Literal['Array', 'Boolean', 'CheckResult', 'Dictionary', 'Function', 'Host', 'Namespace', 'Number', 'Object', 'Service', 'String', 'Timestamp', 'Type', 'uint_fast64_t', 'unsigned long', 'unsigned short', 'Value'], value: Any)[source]
Bases:
object
pretiac.raw_client
Icinga 2 API client
The Icinga 2 API allows you to manage configuration objects and resources in a simple, programmatic way using HTTP requests.
- class pretiac.raw_client.ObjectsUrlEndpoint(client: RawClient)[source]
Bases:
RequestHandlerConnects to the URL endpoint
objectsof the Icinga2 API.Provides methods to manage configuration objects:
creating objects
querying objects
modifying objects
deleting objects
- path_prefix
for example
objectsforlocalhost:5665/v1/objects
- list(object_type: Literal['ApiUser', 'CheckCommand', 'Dependency', 'Endpoint', 'EventCommand', 'Host', 'HostGroup', 'Notification', 'NotificationCommand', 'ScheduledDowntime', 'Service', 'ServiceGroup', 'TimePeriod', 'User', 'UserGroup', 'Zone', 'Comment', 'Downtime', 'ApiListener', 'CheckerComponent', 'CompatLogger', 'ElasticsearchWriter', 'ExternalCommandListener', 'FileLogger', 'GelfWriter', 'GraphiteWriter', 'IcingaApplication', 'IcingaDB', 'IdoMySqlConnection', 'IdoPgsqlConnection', 'InfluxdbWriter', 'Influxdb2Writer', 'JournaldLogger', 'LiveStatusListener', 'NotificationComponent', 'OpenTsdbWriter', 'PerfdataWriter', 'SyslogLogger', 'WindowsEventLogLogger'], name: str | None = None, attrs: Sequence[str] | None = None, filters: str | None = None, filter_vars: dict[str, Any] | None = None, joins: bool | Sequence[str] | None = None, suppress_exception: bool | None = None) Any[source]
get object by type or name
- Parameters:
object_type – The type of the object, for example
Service,HostorUser.name – The full object name, for example
example.localdomainorexample.localdomain!http.attrs – only return these attributes
filters – filters matched object(s)
filter_vars – variables used in the filters expression
joins – show joined object
suppress_exception – If this parameter is set to
True, no exceptions are thrown.
Get all hosts:
raw_client.objects.list("Host")
List the service
ping4of hostwebserver01.domain!ping4:raw_client.objects.list("Service", "webserver01.domain!ping4")
Get all hosts but limit attributes to address and state:
raw_client.objects.list("Host", attrs=["address", "state"])
Get all hosts which have
webserverin their host name:raw_client.objects.list("Host", filters='match("webserver*", host.name)')
Get all services and the joined host name:
raw_client.objects.list("Service", joins=["host.name"])
Get all services and all supported joins:
raw_client.objects.list("Service", joins=True)
Get all services which names start with
vHostand are assigned to hosts namedwebserver*usingfilter_vars:hostname_pattern = "webserver*" service_pattern = "vHost*" raw_client.objects.list( "Service", filters="match(hpattern, host.name) && match(spattern, service.name)", filter_vars={"hpattern": hostname_pattern, "spattern": service_pattern}, )
- get(object_type: Literal['ApiUser', 'CheckCommand', 'Dependency', 'Endpoint', 'EventCommand', 'Host', 'HostGroup', 'Notification', 'NotificationCommand', 'ScheduledDowntime', 'Service', 'ServiceGroup', 'TimePeriod', 'User', 'UserGroup', 'Zone', 'Comment', 'Downtime', 'ApiListener', 'CheckerComponent', 'CompatLogger', 'ElasticsearchWriter', 'ExternalCommandListener', 'FileLogger', 'GelfWriter', 'GraphiteWriter', 'IcingaApplication', 'IcingaDB', 'IdoMySqlConnection', 'IdoPgsqlConnection', 'InfluxdbWriter', 'Influxdb2Writer', 'JournaldLogger', 'LiveStatusListener', 'NotificationComponent', 'OpenTsdbWriter', 'PerfdataWriter', 'SyslogLogger', 'WindowsEventLogLogger'], name: str, attrs: Sequence[str] | None = None, joins: bool | Sequence[str] | None = None, suppress_exception: bool | None = None) Any[source]
Get a single object (
Host,Service, …).- Parameters:
object_type – The type of the object, for example
Service,HostorUser.name – The full object name, for example
example.localdomainorexample.localdomain!http.attrs – Get only the specified objects attributes.
joins – Also get the joined object, e.g. for a Service the Host object.
suppress_exception – If this parameter is set to
True, no exceptions are thrown.
Get host
webserver01.domain:raw_client.objects.get("Host", "webserver01.domain")
Get service
ping4of hostwebserver01.domain:raw_client.objects.get("Service", "webserver01.domain!ping4")
Get host
webserver01.domainbut the attributesaddressandstate:raw_client.objects.get( "Host", "webserver01.domain", attrs=["address", "state"] )
Get service
ping4of hostwebserver01.domainand the host attributes:raw_client.objects.get("Service", "webserver01.domain!ping4", joins=True)
- create(object_type: Literal['ApiUser', 'CheckCommand', 'Dependency', 'Endpoint', 'EventCommand', 'Host', 'HostGroup', 'Notification', 'NotificationCommand', 'ScheduledDowntime', 'Service', 'ServiceGroup', 'TimePeriod', 'User', 'UserGroup', 'Zone', 'Comment', 'Downtime', 'ApiListener', 'CheckerComponent', 'CompatLogger', 'ElasticsearchWriter', 'ExternalCommandListener', 'FileLogger', 'GelfWriter', 'GraphiteWriter', 'IcingaApplication', 'IcingaDB', 'IdoMySqlConnection', 'IdoPgsqlConnection', 'InfluxdbWriter', 'Influxdb2Writer', 'JournaldLogger', 'LiveStatusListener', 'NotificationComponent', 'OpenTsdbWriter', 'PerfdataWriter', 'SyslogLogger', 'WindowsEventLogLogger'], name: str, templates: Sequence[str] | None = None, attrs: dict[str, Any] | None = None, suppress_exception: bool | None = None) Any[source]
Create an object using
templatesand specify attributes (attrs).- Parameters:
object_type – The type of the object, for example
Service,HostorUser.name – The full object name, for example
example.localdomainorexample.localdomain!http.templates – Import existing configuration templates for this object type. Note: These templates must either be statically configured or provided in config packages.
attrs – Set specific object attributes for this object type.
suppress_exception – If this parameter is set to
True, no exceptions are thrown.
Create a host:
raw_client.objects.create( "Host", "localhost", ["generic-host"], {"address": "127.0.0.1"} )
Create a service for Host
localhost:raw_client.objects.create( "Service", "testhost3!dummy", {"check_command": "dummy"}, ["generic-service"], )
- update(object_type: Literal['ApiUser', 'CheckCommand', 'Dependency', 'Endpoint', 'EventCommand', 'Host', 'HostGroup', 'Notification', 'NotificationCommand', 'ScheduledDowntime', 'Service', 'ServiceGroup', 'TimePeriod', 'User', 'UserGroup', 'Zone', 'Comment', 'Downtime', 'ApiListener', 'CheckerComponent', 'CompatLogger', 'ElasticsearchWriter', 'ExternalCommandListener', 'FileLogger', 'GelfWriter', 'GraphiteWriter', 'IcingaApplication', 'IcingaDB', 'IdoMySqlConnection', 'IdoPgsqlConnection', 'InfluxdbWriter', 'Influxdb2Writer', 'JournaldLogger', 'LiveStatusListener', 'NotificationComponent', 'OpenTsdbWriter', 'PerfdataWriter', 'SyslogLogger', 'WindowsEventLogLogger'], name: str, attrs: dict[str, Any], suppress_exception: bool | None = None) Any[source]
Update an object with the specified attributes.
- Parameters:
object_type – The type of the object, for example
Service,HostorUser.name – the name of the object
attrs – object’s attributes to change
suppress_exception – If this parameter is set to
True, no exceptions are thrown.
Change the ip address of a host:
raw_client.objects.update("Host", "localhost", {"address": "127.0.1.1"})
Update a service and change the check interval:
raw_client.objects.update( "Service", "testhost3!dummy", {"check_interval": "10m"} )
- delete(object_type: Literal['ApiUser', 'CheckCommand', 'Dependency', 'Endpoint', 'EventCommand', 'Host', 'HostGroup', 'Notification', 'NotificationCommand', 'ScheduledDowntime', 'Service', 'ServiceGroup', 'TimePeriod', 'User', 'UserGroup', 'Zone', 'Comment', 'Downtime', 'ApiListener', 'CheckerComponent', 'CompatLogger', 'ElasticsearchWriter', 'ExternalCommandListener', 'FileLogger', 'GelfWriter', 'GraphiteWriter', 'IcingaApplication', 'IcingaDB', 'IdoMySqlConnection', 'IdoPgsqlConnection', 'InfluxdbWriter', 'Influxdb2Writer', 'JournaldLogger', 'LiveStatusListener', 'NotificationComponent', 'OpenTsdbWriter', 'PerfdataWriter', 'SyslogLogger', 'WindowsEventLogLogger'], name: str | None = None, filters: str | None = None, filter_vars: dict[str, Any] | None = None, cascade: bool = True, suppress_exception: bool | None = None) Any[source]
Delete an object.
- Parameters:
object_type – The type of the object, for example
Service,HostorUser.name – The full object name, for example
example.localdomainorexample.localdomain!http.filters – filters matched object(s)
filter_vars – variables used in the filters expression
cascade – Delete objects depending on the deleted objects (e.g. services on a host).
suppress_exception – If this parameter is set to
True, no exceptions are thrown.
Delete the
localhost:raw_client.objects.delete("Host", "localhost")
Delete all services matching
vhost*:raw_client.objects.delete( "Service", filters='match("vhost*", service.name)' )
- class pretiac.raw_client.ActionsUrlEndpoint(client: RawClient)[source]
Bases:
RequestHandlerConnects to the URL endpoint
actionsof the Icinga2 API.There are several actions available for Icinga 2 provided by the
/v1/actionsURL endpoint.The following actions are also used by Icinga Web 2:
sending check results to Icinga from scripts, remote agents, etc.
scheduling downtimes from external scripts or cronjobs
acknowledging problems
adding comments
https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#actions
- path_prefix
for example
objectsforlocalhost:5665/v1/objects
- process_check_result(type: Literal['Host', 'Service'], name: str, exit_status: HostState | ServiceState | Literal[0, 1, 2, 3] | int, plugin_output: str, performance_data: Sequence[str] | str | None = None, check_command: Sequence[str] | str | None = None, check_source: str | None = None, execution_start: float | None = None, execution_end: float | None = None, ttl: int | None = None, filter: str | None = None, filter_vars: dict[str, Any] | None = None, suppress_exception: bool | None = None) Any[source]
Process a check result for a host or a service.
Send a
POSTrequest to the URL endpointactions/process-check-result.- Parameters:
type –
HostorService.name – The name of the object.
exit_status – For services:
0=OK,1=WARNING,2=CRITICAL,3=UNKNOWN, for hosts:0=UP,1=DOWN.plugin_output – One or more lines of the plugin main output. Does not contain the performance data.
check_command – The first entry should be the check commands path, then one entry for each command line option followed by an entry for each of its argument. Alternativly a single string can be used.
check_source – Usually the name of the
command_endpoint.execution_start – The timestamp where a script/process started its execution.
execution_end – The timestamp where a script/process ended its execution. This timestamp is used in features to determine e.g. the metric timestamp.
ttl – Time-to-live duration in seconds for this check result. The next expected check result is
now + ttlwhere freshness checks are executed.filter – filters matched object(s)
filter_vars – variables used in the filters expression
suppress_exception – If this parameter is set to
True, no exceptions are thrown.
- Returns:
the response as json
raw_client.process_check_result( "Service", "myhost.domain!ping4", exit_status=2, plugin_output="PING CRITICAL - Packet loss = 100%", performance_data=[ "rta=5000.000000ms;3000.000000;5000.000000;0.000000", "pl=100%;80;100;0", ], check_source="python client", )
- reschedule_check(object_type: Literal['Host', 'Service'], filters: str, filter_vars: dict[str, Any] | None = None, next_check: int | None = None, force_check: bool | None = True) Any[source]
Reschedule a check for hosts and services.
example 1:
raw_client.reschedule_check("Service", 'service.name=="ping4"')
example 2:
raw_client.reschedule_check("Host", 'host.name=="localhost"', 1577833200)
- Parameters:
object_type – Host or Service
filters – filters matched object(s)
filter_vars – variables used in the for filters expression
next_check – timestamp to run the check
force – ignore period restrictions and disabled checks
- Returns:
the response as json
- See:
Icinga2 API documentation: doc/12-icinga2-api/#reschedule-check
- send_custom_notification(object_type: Literal['Host', 'Service'], filters: str, author: str, comment: str, filter_vars: dict[str, Any] | None = None, force: int | None = False) Any[source]
Send a custom notification for hosts and services.
example 1:
send_custom_notification( "Host", "host.name==localhost", "icingaadmin", "test comment" )
- Parameters:
object_type – Host or Service
filters – filters matched object
author – name of the author
comment – comment text
force – ignore downtimes and notification settings
filter_vars – variables used in the filters expression
- Returns:
the response as json
- See:
Icinga2 API documentation: doc/12-icinga2-api/#send-custom-notification
- delay_notification(object_type: Literal['Host', 'Service'], filters: str, timestamp: int, filter_vars: dict[str, Any] | None = None) Any[source]
Delay notifications for a host or a service.
example 1:
delay_notification("Service", "1446389894") delay_notification("Host", 'host.name=="localhost"', "1446389894")
- Parameters:
object_type – Host or Service
filters – filters matched object(s)
timestamp – timestamp to delay the notifications to
filter_vars – variables used in the filters expression
- Returns:
the response as json
- See:
Icinga2 API documentation: doc/12-icinga2-api/#delay-notification
- acknowledge_problem(object_type: Literal['Host', 'Service'], filters: str, author: str, comment: str, filter_vars: dict[str, Any] | None = None, expiry: int | None = None, sticky: bool | None = None, notify: bool | None = None, persistent: bool | None = None) Any[source]
Acknowledge a Service or Host problem.
- Parameters:
object_type – Host or Service
filters – filters matched object(s)
author – name of the author
comment – comment text
filter_vars – variables used in the filters expression
expiry – acknowledgement expiry timestamp
sticky – stay till full problem recovery
notify – send notification
persistent – the comment will remain after the acknowledgement recovers or expires
- Returns:
the response as json
- See:
Icinga2 API documentation: doc/12-icinga2-api/#acknowledge-problem
- remove_acknowledgement(object_type: Literal['Host', 'Service'], filters: str, filter_vars: dict[str, Any] | None = None) Any[source]
Remove the acknowledgement for services or hosts.
example 1:
raw_client.actions.remove_acknowledgement( object_type="Service", filters="service.state==2" )
- Parameters:
object_type – Host or Service
filters – filters matched object(s)
filter_vars – variables used in the filters expression
- Returns:
the response as json
- See:
Icinga2 API documentation: doc/12-icinga2-api/#remove-acknowledgement
- add_comment(object_type: Literal['Host', 'Service'], filter: str, author: str, comment: str, filter_vars: dict[str, Any] | None = None) Any[source]
Add a
commentfrom anauthorto services or hosts.example 1:
raw_client.actions.add_comment( "Service", 'service.name=="ping4"', "icingaadmin", "Troubleticket #123456789 opened.", )
- Parameters:
object_type – The valid types for this action are Host and Service.
filter – filters matched object(s)
author – name of the author
comment – comment text
filter_vars – variables used in the filters expression
- Returns:
the response as json
- See:
- remove_comment(object_type: Literal['Host', 'Service'], name: str | None = None, filters: str | None = None, filter_vars: dict[str, Any] | None = None) Any[source]
Remove a comment using its name or filters.
example 1:
remove_comment("Commentlocalhost!localhost-1458202056-25")
example 2:
remove_comment('Service' filters='service.name=="ping4"')
- Parameters:
object_type – Host, Service or Comment
name – name of the Comment
filters – filters matched object(s)
filter_vars – variables used in the filters expression
- Returns:
the response as json
- See:
Icinga2 API documentation: doc/12-icinga2-api/#remove-comment
- schedule_downtime(object_type: Literal['Host', 'Service'], filters: str, author: str, comment: str, start_time: int, end_time: int, duration: int, filter_vars: dict[str, Any] | None = None, fixed: bool | None = None, all_services: bool | None = None, trigger_name: str | None = None, child_options: str | None = None) Any[source]
Schedule a downtime for hosts and services.
example 1:
schedule_downtime( 'object_type': 'Service', 'filters': r'service.name=="ping4"', 'author': 'icingaadmin', 'comment': 'IPv4 network maintenance', 'start_time': 1446388806, 'end_time': 1446389806, 'duration': 1000 )
example 2:
schedule_downtime( 'object_type': 'Host', 'filters': r'match("*", host.name)', 'author': 'icingaadmin', 'comment': 'IPv4 network maintenance', 'start_time': 1446388806, 'end_time': 1446389806, 'duration': 1000 )
- Parameters:
object_type – Host or Service
filters – filters matched object(s)
author – name of the author
comment – comment text
start_time – timestamp marking the beginning
end_time – timestamp marking the end
duration – duration of the downtime in seconds
filter_vars – variables used in the filters expression
fixed – fixed or flexible downtime
all_services – sets downtime for all services for the matched host objects
trigger_name – trigger for the downtime
child_options – schedule child downtimes.
- Returns:
the response as json
- See:
Icinga2 API documentation: doc/12-icinga2-api/#schedule-downtime
- remove_downtime(object_type: Literal['Host', 'Service'], name: str | None = None, filters: str | None = None, filter_vars: dict[str, Any] | None = None) Any[source]
Remove the downtime using its name or filters.
example 1:
remove_downtime("Downtime", "localhost!ping4!localhost-1458148978-14")
example 2:
remove_downtime("Service", filters='service.name=="ping4"')
- Parameters:
object_type – Host, Service or Downtime
name – name of the downtime
filters – filters matched object(s)
filter_vars – variables used in the filters expression
- Returns:
the response as json
- See:
Icinga2 API documentation: doc/12-icinga2-api/#remove-downtime
- shutdown_process() Any[source]
Shuts down Icinga2. May or may not return.
example 1:
shutdown_process()
- restart_process() Any[source]
Restarts Icinga2. May or may not return.
example 1:
restart_process()
- generate_ticket(cn: str) Any[source]
Generates a PKI ticket for CSR auto-signing. This can be used in combination with satellite/client setups requesting this ticket number.
Example:
raw_client.actions.generate_ticket("my-server-name")
- Parameters:
cn – Required. The host’s common name for which the ticket should be generated.
- See:
Icinga2 API documentation: doc/12-icinga2-api/#generate-ticket
- class pretiac.raw_client.EventsUrlEndpoint(client: RawClient)[source]
Bases:
RequestHandlerConnects to the URL endpoint
eventsof the Icinga2 API.- path_prefix
for example
objectsforlocalhost:5665/v1/objects
- subscribe(types: Sequence[Literal['CheckResult', 'StateChange', 'Notification', 'AcknowledgementSet', 'AcknowledgementCleared', 'CommentAdded', 'CommentRemoved', 'DowntimeAdded', 'DowntimeRemoved', 'DowntimeStarted', 'DowntimeTriggered', 'ObjectCreated', 'ObjectDeleted', 'ObjectModified']], queue: str, filter: str | None = None, filter_vars: dict[str, Any] | None = None) Generator[str | Any, Any, None][source]
Subscribe to an event stream.
Event streams can be used to receive check results, downtimes, comments, acknowledgements, etc. as a “live stream” from Icinga.
You can for example forward these types into your own backend. Process the metrics and correlate them with notifications and state changes e.g. in Elasticsearch with the help of Icingabeat. Another use case are aligned events and creating/resolving tickets automatically in your ticket system.
You can subscribe to event streams by sending a POST request to the URL endpoint /v1/events. The following parameters need to be specified (either as URL parameters or in a JSON-encoded message body):
example 1:
types = ["CheckResult"] queue = "monitor" filters = "event.check_result.exit_status==2" for event in subscribe(types, queue, filters): print event
- Parameters:
types – Required. Event type(s). Multiple types as URL parameters are supported.
queue – Required. Unique queue name. Multiple HTTP clients can use the same queue as long as they use the same event types and filter.
filter – Filter for specific event attributes using filter expressions.
filter_vars – variables used in the filters expression
- Returns:
the events
- See:
Icinga2 API documentation: doc/12-icinga2-api/#event-streams
- class pretiac.raw_client.StatusUrlEndpoint(client: RawClient)[source]
Bases:
RequestHandlerConnects to the URL endpoint
statusof the Icinga2 API.- path_prefix
for example
objectsforlocalhost:5665/v1/objects
- list(status_type: Literal['ApiListener', 'CIB', 'CheckerComponent', 'ElasticsearchWriter', 'FileLogger', 'GelfWriter', 'GraphiteWriter', 'IcingaApplication', 'IdoMysqlConnection', 'IdoPgsqlConnection', 'Influxdb2Writer', 'InfluxdbWriter', 'JournaldLogger', 'NotificationComponent', 'OpenTsdbWriter', 'PerfdataWriter', 'SyslogLogger'] | str | None = None) Any[source]
Retrieve status information and statistics for Icinga 2.
List complete status:
.. code-block:: python
client.status.list()
List the status of the core application:
client.status.list("IcingaApplication")
- Parameters:
status_type – Limit the output by specifying a status type, e.g.
IcingaApplication.- Returns:
status information
- See:
- class pretiac.raw_client.ConfigUrlEndpoint(client: RawClient)[source]
Bases:
RequestHandlerConnects to the URL endpoint
configof the Icinga2 API.Manage configuration packages and stages based on configuration files and directory trees.
- path_prefix
for example
objectsforlocalhost:5665/v1/objects
- create_package(package_name: str, suppress_exception: bool | None = None) Any[source]
Create a new empty configuration package.
- Parameters:
package_name – Package names with the
_prefix are reserved for internal packages and must not be used. You can recognize_api,_etcand_clusterwhen querying specific objects and packages.suppress_exception – If this parameter is set to
True, no exceptions are thrown.
- See:
Icinga2 API documentation: doc/12-icinga2-api/#create-a-config-package
- create_stage(package_name: str, files: dict[str, str], reload: bool | None = None, activate: bool | None = None, suppress_exception: bool | None = None) Any[source]
Configuration files in packages are managed in stages. Stages provide a way to maintain multiple configuration versions for a package. Once a new stage is deployed, the content is validated and set as active stage on success.
On failure, the older stage remains active, and the caller can fetch the startup.log from this stage deployment attempt to see what exactly failed. You can see that in the Director’s deployment log.
- Parameters:
package_name – Package names with the
_prefix are reserved for internal packages and must not be used. You can recognize_api,_etcand_clusterwhen querying specific objects and packages.files – Dictionary of file targets and their content.
reload – Tell icinga2 to reload after stage config validation (defaults to
true).activate – Tell icinga2 to activate the stage if it validates (defaults to
true). If activate is set to false, reload must also be false.suppress_exception – If this parameter is set to
True, no exceptions are thrown.
Example for a local configuration in the
conf.ddirectory:raw_client.configuration.create_stage( package_name="example-cmdb", files={ "conf.d/test-host.conf": 'object Host "test-host" { address = "127.0.0.1", check_command = "hostalive" }' }, )
Example for a host configuration inside the
satellitezone in thezones.ddirectory:raw_client.configuration.create_stage( package_name="example-cmdb", files={ "zones.d/satellite/host2.conf": 'object Host "satellite-host" { address = "192.168.1.100", check_command = "hostalive"', }, )
- list_packages(suppress_exception: bool | None = None) Any[source]
List packages and their stages.
- Parameters:
suppress_exception – If this parameter is set to
True, no exceptions are thrown.- See:
Icinga2 API documentation: doc/12-icinga2-api/#list-configuration-packages-and-their-stages
- list_stage_files(package_name: str, stage_name: str, suppress_exception: bool | None = None) Any[source]
List packages and their stages.
- Parameters:
package_name – Package names with the
_prefix are reserved for internal packages and must not be used. You can recognize_api,_etcand_clusterwhen querying specific objects and packages.stage_name – The stage name, for example
7e7861c8-8008-4e8d-9910-2a0bb26921bd.suppress_exception – If this parameter is set to
True, no exceptions are thrown.
- See:
Icinga2 API documentation: doc/12-icinga2-api/#list-configuration-package-stage-files
- fetch_stage_file(package_name: str, stage_name: str, relpath: str, suppress_exception: bool | None = None) str[source]
Fetch the content of a specific configuration file
- Parameters:
package_name – Package names with the
_prefix are reserved for internal packages and must not be used. You can recognize_api,_etcand_clusterwhen querying specific objects and packages.stage_name – The stage name, for example
7e7861c8-8008-4e8d-9910-2a0bb26921bd.relpath – The relative path of the requested configuration file.
suppress_exception – If this parameter is set to
True, no exceptions are thrown.
- See:
Icinga2 API documentation: doc/12-icinga2-api/#fetch-configuration-package-stage-files
- get_package_stage_errors(package_name: str, stage_name: str, suppress_exception: bool | None = None) str[source]
Check for validation errors.
- Parameters:
package_name – Package names with the
_prefix are reserved for internal packages and must not be used. You can recognize_api,_etcand_clusterwhen querying specific objects and packages.stage_name – The stage name, for example
7e7861c8-8008-4e8d-9910-2a0bb26921bd.suppress_exception – If this parameter is set to
True, no exceptions are thrown.
- See:
Icinga2 API documentation: doc/12-icinga2-api/#configuration-package-stage-errors
- delete_stage(package_name: str, stage_name: str, suppress_exception: bool | None = None) Any[source]
Send a delete request in order to purge a configuration stage.
- Parameters:
name – Package names with the
_prefix are reserved for internal packages and must not be used. You can recognize_api,_etcand_clusterwhen querying specific objects and packages.stage_name – The stage name, for example
7e7861c8-8008-4e8d-9910-2a0bb26921bd.suppress_exception – If this parameter is set to
True, no exceptions are thrown.
- See:
Icinga2 API documentation: doc/12-icinga2-api/#deleting-configuration-package-stage
- delete_package(package_name: str, suppress_exception: bool | None = None) Any[source]
Delete the configuration package entirely.
- Parameters:
name – Package names with the
_prefix are reserved for internal packages and must not be used. You can recognize_api,_etcand_clusterwhen querying specific objects and packages.suppress_exception – If this parameter is set to
True, no exceptions are thrown.
- See:
Icinga2 API documentation: doc/12-icinga2-api/#deleting-configuration-package
- class pretiac.raw_client.TypesUrlEndpoint(client: RawClient)[source]
Bases:
RequestHandler- path_prefix
for example
objectsforlocalhost:5665/v1/objects
- list(object_type: Literal['ApiUser', 'CheckCommand', 'Dependency', 'Endpoint', 'EventCommand', 'Host', 'HostGroup', 'Notification', 'NotificationCommand', 'ScheduledDowntime', 'Service', 'ServiceGroup', 'TimePeriod', 'User', 'UserGroup', 'Zone'] | Literal['Comment', 'Downtime'] | Literal['ApiListener', 'CheckerComponent', 'CompatLogger', 'ElasticsearchWriter', 'ExternalCommandListener', 'FileLogger', 'GelfWriter', 'GraphiteWriter', 'IcingaApplication', 'IcingaDB', 'IdoMySqlConnection', 'IdoPgsqlConnection', 'InfluxdbWriter', 'Influxdb2Writer', 'JournaldLogger', 'LiveStatusListener', 'NotificationComponent', 'OpenTsdbWriter', 'PerfdataWriter', 'SyslogLogger', 'WindowsEventLogLogger'] | None = None) Any[source]
Retrieve the configuration object types.
- Parameters:
object_type – The type of the object, for example
Service,HostorUser.- See:
- class pretiac.raw_client.TemplatesUrlEndpoint(client: RawClient)[source]
Bases:
RequestHandlerConnects to the URL endpoint
templatesof the Icinga2 API.- path_prefix
for example
objectsforlocalhost:5665/v1/objects
- list(object_type: Literal['ApiUser', 'CheckCommand', 'Dependency', 'Endpoint', 'EventCommand', 'Host', 'HostGroup', 'Notification', 'NotificationCommand', 'ScheduledDowntime', 'Service', 'ServiceGroup', 'TimePeriod', 'User', 'UserGroup', 'Zone', 'Comment', 'Downtime', 'ApiListener', 'CheckerComponent', 'CompatLogger', 'ElasticsearchWriter', 'ExternalCommandListener', 'FileLogger', 'GelfWriter', 'GraphiteWriter', 'IcingaApplication', 'IcingaDB', 'IdoMySqlConnection', 'IdoPgsqlConnection', 'InfluxdbWriter', 'Influxdb2Writer', 'JournaldLogger', 'LiveStatusListener', 'NotificationComponent', 'OpenTsdbWriter', 'PerfdataWriter', 'SyslogLogger', 'WindowsEventLogLogger'], filter: str | None = None) Any[source]
Request information about configuration templates.
- Parameters:
object_type – The type of the object, for example
Service,HostorUser.filter – The template object can be accessed in the filter using the
tmplvariable. In the example"match("g*", tmpl.name)"the match function is used to check a wildcard string pattern againsttmpl.name.
- See:
Icinga2 API documentation: doc/12-icinga2-api/#querying-templates
- class pretiac.raw_client.VariablesUrlEndpoint(client: RawClient)[source]
Bases:
RequestHandler- path_prefix
for example
objectsforlocalhost:5665/v1/objects
- class pretiac.raw_client.ConsoleUrlEndpoint(client: RawClient)[source]
Bases:
RequestHandler- path_prefix
for example
objectsforlocalhost:5665/v1/objects
- class pretiac.raw_client.RawClient(config: Config)[source]
Bases:
objectThis raw client is a thin wrapper around the Icinga2 REST API.
You can use the client with either username/password combination or using certificates.
Example using username and password:
from pretiac.client import Client client = Client("localhost", 5665, "username", "password")
Example using certificates:
client = Client( "localhost", 5665, certificate="/etc/ssl/certs/myhostname.crt", key="/etc/ssl/keys/myhostname.key", )
If your public and private are in the same file, just use the certificate parameter.
To verify the server certificate specify a ca file as ca_file parameter.
Example:
from pretiac.client import Client client = Client( "https://icinga2:5665", certificate="/etc/ssl/certs/myhostname.crt", key="/etc/ssl/keys/myhostname.key", ca_file="/etc/ssl/certs/my_ca.crt", )
- objects: ObjectsUrlEndpoint
Connects to the URL endpoint
objectsof the Icinga2 API.
- actions: ActionsUrlEndpoint
Connects to the URL endpoint
actionsof the Icinga2 API.
- events: EventsUrlEndpoint
Connects to the URL endpoint
eventsof the Icinga2 API.
- status: StatusUrlEndpoint
Connects to the URL endpoint
statusof the Icinga2 API.
- config: ConfigUrlEndpoint
Connects to the URL endpoint
configof the Icinga2 API.
- types: TypesUrlEndpoint
Connects to the URL endpoint
typesof the Icinga2 API.
- templates: TemplatesUrlEndpoint
Connects to the URL endpoint
templatesof the Icinga2 API.
- variables: VariablesUrlEndpoint
Connects to the URL endpoint
typesof the Icinga2 API.
- console: ConsoleUrlEndpoint
Connects to the URL endpoint
typesof the Icinga2 API.
pretiac.request_handler
Provides the base class RequestHandler that is inherited by the different
endpoint classes, for example the class Events handles the v1/events endpoint,
the class Objects handles the v1/objects entpoint and so on…
- pretiac.request_handler.normalize_state(state: HostState | ServiceState | Literal[0, 1, 2, 3] | int | Any) int[source]