Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
324366e
Correct python coding line
Mar 7, 2016
e09f15b
Use print function
Mar 7, 2016
745db1e
Use format() function to format strings
Mar 7, 2016
9858195
Add docstrings to classes
Mar 7, 2016
6ac213e
apply pep8
Mar 7, 2016
6487b65
Fix missing dot
Mar 7, 2016
4c47e6a
Use requests session method
Mar 7, 2016
640a2ae
Add possibility to show only specific attributes
Mar 7, 2016
1c58e61
Add version attribute to Client and use it in HTTP header
Mar 8, 2016
c1e5049
Allow usage without CA certificate
Mar 8, 2016
321088d
Add docstring to list function and use Icinga 2 object type names
Mar 8, 2016
617c356
Add attribute "joins" to list function
Mar 8, 2016
61e4e07
Correct example for usage of "joins" in list function
Mar 8, 2016
bec9b48
Add all icinga 2 object types to objects.list function
Mar 8, 2016
a64e8e4
Introduce function objects._convert_object_type
Mar 8, 2016
2aebc1e
Add example for specifying "all_joins" for objects.list
Mar 8, 2016
9199bca
Extend objects.create function
Mar 9, 2016
1d737b9
Extend objects.update function
Mar 9, 2016
31696fc
Fix typos
Mar 9, 2016
2c82fbf
Extend objects.delete function
Mar 9, 2016
32020be
Use "payload" variable consistenly
Mar 9, 2016
dfb3490
Raise exception when return HTTP return code is not in 200..299
Mar 9, 2016
5f3f4c6
Use urljoin to create request url
Mar 9, 2016
bb49062
Add docstring to _request function
Mar 9, 2016
1a4af57
Use variable name "response" because it is one
Mar 9, 2016
070a778
Remove default values for parameters in _request function
Mar 9, 2016
42be7ed
Enhance status.list() function
Mar 9, 2016
407ebf2
Add possibility to get config from a file
Mar 10, 2016
f495148
Rename some variables
Mar 10, 2016
5d2052b
Pylint
Mar 10, 2016
59c420e
Correctly call super Exception __init__()
Mar 10, 2016
4dd00b4
pylint
Mar 10, 2016
c1c0ec4
Use object_type as parameter for process_check_result function
Mar 16, 2016
70bd801
Re-work actions.schedule_downtime function
Mar 17, 2016
a37fa3b
Replace double quotes with single quotes for docstrings
Mar 17, 2016
1f23dd0
Re-work actions.restart_process function
Mar 17, 2016
5fdb1ef
Re-work actions.shutdown_process function
Mar 17, 2016
c76fc9f
Re-work actions.remove_downtime function
Mar 17, 2016
3a5b8b5
Replace double quotes with single quotes in actions.schedule_downtime…
Mar 17, 2016
4a8af10
Re-work actions.add_comment function
Mar 17, 2016
12cb12b
Re-work actions.remove_comment function
Mar 17, 2016
da85e22
Update README
Mar 10, 2016
c71e3e3
Re-work actions.remove_acknowledgement function
Mar 22, 2016
89a6dbe
Re-work actions.acknowledge_problem function
Mar 22, 2016
a4b29f4
Re-work actions.send_custom_notification function
Mar 22, 2016
f502bf1
Re-work actions.reschedule_check function
Mar 22, 2016
1d6152a
Re-work actions.process_check_result function
Mar 22, 2016
492a022
Re-work events.subscribe function and add _get_message_from_stream fu…
Apr 9, 2016
e28be16
Add me to the setup.py file
Apr 9, 2016
d65a93f
Fix typo in schedule_downtime examples
Apr 25, 2016
56b70b8
Remove debugging print function calls
Apr 25, 2016
5c11c7b
Add objects.get() function
Apr 25, 2016
700af72
Fix initialisation without configuration file
Apr 25, 2016
da20c8b
Fix flake8: E265 block comment should start with '# '
Apr 25, 2016
87843ea
Fix flake8: E713 test for membership should be 'not in'
Apr 25, 2016
abd37f1
Fix flake8: E501 line too long (83 > 79 characters)
Apr 25, 2016
47dcc3b
Fix objects.get() and objects.list()
Apr 25, 2016
4480dba
Fix pylint: Final newline missing
Apr 27, 2016
7717349
Add more parameter checking
May 2, 2016
c283778
Rename function for config file access checking
May 2, 2016
41b46d5
Add client usage with certificate and key to README
May 2, 2016
26fd358
Change example to add a host in the README
May 2, 2016
ee6bdff
Add documentation in markdown format
May 9, 2016
33f104b
Add docstring to __init__.py
May 9, 2016
7d865f3
Rewrite docstring in client.py
May 9, 2016
207155a
Fix objects.get()
May 10, 2016
5ee9522
Rename "filters" to "filter"
Jun 16, 2016
3c1ff65
Add support for 'filter_vars'
Jun 16, 2016
edf5610
Add link to fmnisme's github page
Jun 16, 2016
73377e6
Add link to Icinga 2 API filter documentation
Jun 16, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 11 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,17 @@
#Feature
1. basic auth
2. objects(zone support)
3. actions
4. events
5. status

#Developing
1. cert auth
2. Configuration Management

#Usage
```
from icinga2api.client import Client
client = Client('https://localhost:5665','username','passowrd')
1. basic and certificate auth
1. config file support
1. objects (zone support)
1. actions
1. events
1. status

#list host
```
filters = {
"attrs" : ["name", "address"],
}
client.objects.list('hosts',filters=filters)
```
#Developing

#create host
```
config = {
"templates": [ "generic-host" ],
"attrs": {
"address": "192.168.1.100",
'vars.os': 'Windows',
'vars.services.mysql': {'ports': [3306, 3307]},
'zone' : 'Zone1',
}
}
print client.objects.create('hosts','test1',config)
```
1. Code cleanup
1. Configuration Management

#Usage

**read source commentary for more examples.**
See the **doc** directory.
16 changes: 16 additions & 0 deletions doc/1-about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# <a id="about-icinga2"></a> About python-icinga2api

python-icinga2api is a [Python](http://www.python.org) module to interact with the [Icinga 2 RESTful API](http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/icinga2-api).

## <a id="features"></a> Features

1. basic and certificate auth
1. config file support
1. objects (zone support)
1. actions
1. events
1. status

## <a id="development-info"></a> Development

The code is based on [fmnisme's version](https://github.com/fmnisme/python-icinga2api). Forking, reporting bugs and sending PRs is very appreciated.
49 changes: 49 additions & 0 deletions doc/2-authentication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# <a id="basics"></a> Basics

## <a id="authentication"></a> Authentication

You can use the client with either username/password combination or using certificates.

Example using username and password:

from icinga2api.client import Client
client = Client('https://localhost:5665', 'username', 'password')

Example using certificates:

from icinga2api.client import Client
client = Client('https://icinga2: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.


## <a id="config-file"></a> Config file

You can also specify a config file (in ini format) containing all necessary information.

Example:

client = Client('https://localhost:5665', config_file='/etc/icinga2api')

The config file looks like:

[api]
url = https://icinga2:5665
certificate = /etc/ssl/certs/myhostname.crt
key = /etc/ssl/private/myhostname.key
ca_certificate = /etc/ssl/certs/ca.crt


## <a id="server-verification"></a> Server verification

To verify the server certificate specify a ca file as `ca_file` parameter.

Example:

from icinga2api.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')
149 changes: 149 additions & 0 deletions doc/3-objects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# <a id="objects"></a> Objects

## <a id="objects-get"></a> objects.get()

To get a single object (`Host`, `Service`, ...) use the funtion `objects.get()`.

Parameter | Type | Description
---------------|-----------|------------
object\_type | string | **Required.** The object type to get, e.g. `Host`, `Service`.
name | string | **Required.** The objects name.
attrs | list | **Optional.** Get only the specified objects attributes.
joins | bool | **Optional.** Also get the joined object, e.g. for a `Service` the `Host` object.

Examples:

Get host `webserver01.domain`:

client.objects.get('Host', 'webserver01.domain')

Get service `ping4` of host `webserver01.domain`:

client.objects.get('Service', 'webserver01.domain!ping4')

Get host `webserver01.domain` but the attributes `address` and `state`:

client.objects.get('Host', 'webserver01.domain', attrs=['address', 'state'])

Get service `ping4` of host `webserver01.domain` and the host attributes:

client.objects.get('Service', 'webserver01.domain!ping4', joins=True)

## <a id="objects-list"></a> objects.list()

To get a list of objects (`Host`, `Service`, ...) use the funtion `objects.list()`. You can use `filter` to ...

Parameter | Type | Description
--------------|------------|--------------
object\_type | string | **Required.** The object type to get, e.g. `Host`, `Service`.
name | string | **Optional.** The objects name.
attrs | list | **Optional.** Get only the specified objects attributes.
filter | string | **Optional.** The filter expression, see [documentation](http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/icinga2-api#icinga2-api-filters).
filter\_vars | dictionary | **Optional.** Variables which are available to your filter expression.
joins | bool | **Optional.** Also get the joined object, e.g. for a `Service` the `Host` object.

Examples:

Get all hosts:

client.objects.list('Host')

Get all hosts but limit attributes to `address` and `state`

client.objects.list('Host', attrs=['address', 'state'])

Get all hosts which have "webserver" in their host name

client.objects.list('Host', filter='match("webserver\*", host.name)')

Get all services which names start with "vHost" and are assigned to hosts named "webserver\*" using `filter_vars`

hostname_pattern = 'webserver\*'
service_pattern = 'vHost\*'
client.objects.list('Service',
filter='match(hpattern, host.name) && match(spattern, service.name)',
filter_vars={'hpattern': hostname_pattern, 'spattern': service_pattern})

Get all services and the joined host name:

client.objects.list('Service', joins=['host.name'])


## <a id="objects-create"></a> objects.create()

Create an object using `templates` and specify attributes (`attrs`).

Parameter | Type | Description
--------------|------------|--------------
object\_type | string | **Required.** The object type to get, e.g. `Host`, `Service`.
name | string | **Optional.** The objects name.
templates | list | **Optional.** A list of templates to import.
attrs | dictionary | **Optional.** The objects attributes.

Examples:

Create a host:

client.objects.create(
'Host',
'localhost',
['generic-host'],
{'address': '127.0.0.1'})

Create a service for Host "localhost":

client.objects.create(
'Service',
'localhost!dummy',
['generic-service'],
{'check_command': 'dummy'})


## <a id="objects-update"></a> objects.update()

Update an object with the specified attributes.

Parameter | Type | Description
--------------|------------|--------------
object\_type | string | **Required.** The object type to get, e.g. `Host`, `Service`.
name | string | **Optional.** The objects name.
attrs | dictionary | **Optional.** The objects attributes.

Examples:

Change the ip address of a host:

client.objects.update(
'Host',
'localhost',
{'address': '127.0.1.1'})

Update a service and change the check interval:

client.objects.create('Service',
'localhost!dummy',
['generic-service'],
{'check_interval': '10m'})


## <a id="objects-delete"></a> objects.delete()

Update an object with the specified attributes.

Parameter | Type | Description
--------------|------------|--------------
object\_type | string | **Required.** The object type to get, e.g. `Host`, `Service`.
name | string | **Optional.** The objects name.
filter | string | **Optional.** Filter expression for matching the objects.
filter\_vars | dictionary | **Optional.** Variables which are available to your filter expression.
cascade | boolean | **Optional.** Also delete dependent objects. Defaults to `True`.

Examples:

Delete the "localhost":

client.objects.delete('Host', 'localhost')

Delete all services matching `vhost\*`:

client.objects.delete('Service', filter='match("vhost\*", service.name)')
Loading