icinga2 0.9.0.1 → 0.9.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,26 @@
1
1
  # Icinga2 - Statistics
2
2
 
3
3
 
4
- ## <a name="stats-avg"></a>statistic data for latency and execution_time
5
- average_statistics
4
+ ## <a name="stats-avg"></a>*average_statistics*
5
+
6
+ statistic data for latency and execution_time
7
+
8
+ The result are an `Hash`
6
9
 
7
10
  ### Example
8
11
  @icinga.cib_data
9
12
  latency, execution_time = @icinga.average_statistics.values
10
13
 
11
14
  or
15
+
12
16
  h = @icinga.average_statistics
13
17
  latency = h.dig(:latency)
14
18
 
15
- ## <a name="stats-interval"></a>statistic data for intervall data
16
- interval_statistics
19
+ ## <a name="stats-interval"></a>*interval_statistics*
20
+
21
+ statistic data for intervall data
22
+
23
+ The result are an `Hash`
17
24
 
18
25
  ### Example
19
26
  @icinga.cib_data
@@ -24,8 +31,11 @@ or
24
31
  hosts_active_checks = i.dig(:hosts_active_checks)
25
32
 
26
33
 
27
- ## <a name="stats-services"></a>statistic data for services
28
- service_statistics
34
+ ## <a name="stats-services"></a>*service_statistics*
35
+
36
+ statistic data for services
37
+
38
+ The result are an `Hash`
29
39
 
30
40
  ### Example
31
41
  @icinga.cib_data
@@ -35,19 +45,27 @@ or
35
45
  s = @icinga.service_statistics
36
46
  critical = s.dig(:critical)
37
47
 
38
- ## <a name="stats-hosts"></a>statistic data for hosts
39
- host_statistics
48
+ ## <a name="stats-hosts"></a>*host_statistics*
49
+
50
+ statistic data for hosts
51
+
52
+ The result are an `Hash`
40
53
 
41
54
  ### Example
42
55
  @icinga.cib_data
43
56
  up, down, pending, unreachable, in_downtime, ack = @icinga.host_statistics.values
44
57
 
45
58
  or
59
+
46
60
  h = @icinga.host_statistics
47
61
  pending = h.dig(:pending)
48
62
 
49
- ## <a name="stats-work-queue"></a>queue statistics from the api
50
- work_queue_statistics
63
+
64
+ ## <a name="stats-work-queue"></a>work_queue_statistics
65
+
66
+ queue statistics from the api
67
+
68
+ The result are an `Hash`
51
69
 
52
70
  ### Example
53
71
  @icinga.work_queue_statistics
@@ -1,27 +1,51 @@
1
1
  # Icinga2 - Usergroups
2
2
 
3
3
 
4
- ## <a name="add-usergroup"></a>add a usergroup
5
- add_usergroup( params )
4
+ ## <a name="add-usergroup"></a>*add_usergroup( params )*
5
+
6
+ Creates an Icinga2 Usergroup.
7
+
8
+ `params` are an `Hash` with following Parameters:
9
+
10
+ | Parameter | Type | Example | Description
11
+ | :-------------------- | :-----: | :----- | :-----------
12
+ | `user_group` | String | `foo` | Usergroup they will be created
13
+ | `display_name` | String | `User Foo` | the displayed Name
14
+
15
+ The result are an `Hash`
6
16
 
7
17
  ### Example
8
18
  @icinga.add_usergroup(user_group: 'foo', display_name: 'FOO')
9
19
 
10
20
 
11
- ## <a name="delete-usergroup"></a>delete a usergroup
12
- delete_usergroup( params )
21
+ ## <a name="delete-usergroup"></a>*delete_usergroup( params )*
22
+
23
+ Delete a Usergroup.
24
+
25
+ `params` are an `Hash` with following Parameters:
26
+
27
+ | Parameter | Type | Example | Description
28
+ | :-------------------- | :-----: | :----- | :-----------
29
+ | `user_group` | String | `foo` | Usergroup they will be deleted
30
+
31
+ The result are an `Hash`
13
32
 
14
33
  ### Example
15
34
  @icinga.delete_usergroup(user_group: 'foo')
16
35
 
17
36
 
18
- ## <a name="list-usergroups"></a>list usergroups
37
+ ## <a name="list-usergroups"></a>*usergroups* or *usergroups( params )*
19
38
 
20
- ### list named usergroup
21
- usergroups( params )
39
+ returns all or a named usergroup.
40
+
41
+ the optional `params` is an `Hash` with following Parameters:
42
+
43
+ | Parameter | Type | Example | Description
44
+ | :-------------------- | :-----: | :----- | :-----------
45
+ | `user_group` | String | `foo` | Usergroup they will be listed
46
+
47
+ The result are an `Hash`
22
48
 
23
- #### Example
24
- @icinga.usergroups(user_group: 'icingaadmins')
25
49
 
26
50
  ### list all usergroups
27
51
  usergroups
@@ -30,8 +54,22 @@
30
54
  @icinga.usergroups
31
55
 
32
56
 
33
- ## <a name="usergroup-exists"></a>check if the usergroup exists
34
- exists_usergroup?( user_group )
57
+ ### list named usergroup
58
+ usergroups( params )
59
+
60
+ #### Example
61
+ @icinga.usergroups(user_group: 'icingaadmins')
62
+
63
+
64
+
65
+ ## <a name="usergroup-exists"></a>*exists_usergroup?( user_group )*
66
+
67
+ check if the Usergroup exists
68
+
69
+ `params` is an `String` with the Usergroupname.
70
+
71
+ The result are an `Boolean`
35
72
 
36
73
  ### Example
74
+
37
75
  @icinga.exists_usergroup?('icingaadmins')
@@ -1,9 +1,24 @@
1
1
  # Icinga2 - Users
2
2
 
3
- ## <a name="add-user"></a>add a user
4
- add_user( params )
3
+ ## <a name="add-user"></a>*add_user( params )*
4
+
5
+ creates an Icinga2 User.
6
+
7
+ `params` are an `Hash` with following Parameters:
8
+
9
+ | Parameter | Type | Example | Description
10
+ | :-------------------- | :-----: | :----- | :-----------
11
+ | `user_name` | String | `foo` | User they will be created
12
+ | `display_name` | String | `User Foo` | the displayed Name
13
+ | `email` | String | `foo@bar.tld` | the Email for this Users
14
+ | `pager` | String | `+49 000 000000` | an optional Pager Number
15
+ | `enable_notifications` | Bool | `true` | enable notifications for this user (default: **false**)
16
+ | `groups` | Array | `['icingaadmins','dba']` | a hash with (existing!) groups
17
+
18
+ The result are an `Hash`
5
19
 
6
20
  ### Example
21
+
7
22
  params = {
8
23
  user_name: 'foo',
9
24
  display_name: 'FOO',
@@ -11,29 +26,65 @@
11
26
  pager: '0000',
12
27
  groups: ['icingaadmins']
13
28
  }
14
- @icinga.add_user( params )
29
+ puts @icinga.add_user( params )
30
+ {"code"=>200, "name"=>nil, "status"=>"Object was created"}
31
+
32
+
33
+ ## <a name="delete-user"></a>*delete_user( params )*
15
34
 
35
+ delete an Icinga2 User.
16
36
 
17
- ## <a name="delete-user"></a>delete a user
18
- delete_user( params )
37
+ `params` is an `Hash` with following Parameters:
38
+
39
+ | Parameter | Type | Example | Description
40
+ | :-------------------- | :-----: | :----- | :-----------
41
+ | `user_name` | String | `foo` | User they will be deleted
42
+
43
+ The result are an `Hash`
19
44
 
20
45
  ### Example
21
- @icinga.delete_user(user_name: 'foo')
22
46
 
47
+ puts @icinga.delete_user(user_name: 'foo')
48
+ {"code"=>200, "name"=>"foo", "status"=>"Object was deleted."}
23
49
 
24
- ## <a name="list-users"></a>list users
25
- ### list named user
26
- users( params )
27
- #### Example
28
- @icinga.users(user_name: 'icingaadmin')
50
+
51
+ ## <a name="list-users"></a>*users* or *users( params )*
52
+
53
+ returns all or a named user.
54
+
55
+ the optional `params` is an `Hash` with following Parameters:
56
+
57
+ | Parameter | Type | Example | Description
58
+ | :-------------------- | :-----: | :----- | :-----------
59
+ | `user_name` | String | `foo` | User they will be listed
60
+
61
+ The result are an `Hash`
29
62
 
30
63
  ### list all users
31
64
  users
65
+
32
66
  #### Example
33
67
  @icinga.users
68
+ {"attrs"=>{"__name"=>"icingaadmin", "active"=>true, "display_name"=>"Icinga 2 Admin", "email"=>"icinga@localhost", "enable_notifications"=>true, "groups"=>["icingaadmins"], "ha_mode"=>0.0, "last_notification"=>0.0, "name"=>"icingaadmin", "original_attributes"=>nil, "package"=>"_etc", "pager"=>"", "paused"=>false, "period"=>"", "source_location"=>{"first_column"=>1.0, "first_line"=>6.0, "last_column"=>25.0, "last_line"=>6.0, "path"=>"/etc/icinga2/conf.d/users.conf"}, "states"=>nil, "templates"=>["icingaadmin", "generic-user"], "type"=>"User", "types"=>nil, "vars"=>nil, "version"=>0.0, "zone"=>""}, "joins"=>{}, "meta"=>{}, "name"=>"icingaadmin", "type"=>"User"}
69
+
70
+ ### list named user
71
+ users( params )
34
72
 
73
+ #### Example
74
+ @icinga.users(user_name: 'foo')
75
+ {"attrs"=>{"__name"=>"foo", "active"=>true, "display_name"=>"FOO", "email"=>"foo@bar.com", "enable_notifications"=>false, "groups"=>["icingaadmins"], "ha_mode"=>0.0, "last_notification"=>0.0, "name"=>"foo", "original_attributes"=>nil, "package"=>"_api", "pager"=>"0000", "paused"=>false, "period"=>"", "source_location"=>{"first_column"=>0.0, "first_line"=>1.0, "last_column"=>16.0, "last_line"=>1.0, "path"=>"/var/lib/icinga2/api/packages/_api/icinga2-master.matrix.lan-1507365860-1/conf.d/users/foo.conf"}, "states"=>nil, "templates"=>["foo"], "type"=>"User", "types"=>nil, "vars"=>nil, "version"=>1507609817.587105, "zone"=>"icinga2-master.matrix.lan"}, "joins"=>{}, "meta"=>{}, "name"=>"foo", "type"=>"User"}
76
+
77
+
78
+
79
+ ## <a name="user-exists"></a>*exists_user?( params )*
35
80
 
36
- ## <a name="user-exists"></a>checks if the user exists
81
+ check if an User exists.
82
+
83
+ `params` is an `String` with the Username.
84
+
85
+ The result are an `Boolean`
37
86
 
38
87
  ### Example
39
- @icinga.exists_user?('icingaadmin')
88
+
89
+ puts @icinga.exists_user?('icingaadmin')
90
+ true
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # 07.10.2017 - Bodo Schulz
5
+ #
6
+ #
7
+ # Examples for Hostgroups
8
+
9
+ # -----------------------------------------------------------------------------
10
+
11
+ require_relative '../lib/icinga2'
12
+
13
+ # -----------------------------------------------------------------------------
14
+
15
+ icinga_host = ENV.fetch( 'ICINGA_HOST' , 'icinga2' )
16
+ icinga_api_port = ENV.fetch( 'ICINGA_API_PORT' , 5665 )
17
+ icinga_api_user = ENV.fetch( 'ICINGA_API_USER' , 'admin' )
18
+ icinga_api_pass = ENV.fetch( 'ICINGA_API_PASSWORD' , nil )
19
+ icinga_api_pki_path = ENV.fetch( 'ICINGA_API_PKI_PATH' , '/etc/icinga2' )
20
+ icinga_api_node_name = ENV.fetch( 'ICINGA_API_NODE_NAME' , nil )
21
+ icinga_cluster = ENV.fetch( 'ICINGA_CLUSTER' , false )
22
+ icinga_satellite = ENV.fetch( 'ICINGA_CLUSTER_SATELLITE', nil )
23
+
24
+
25
+ # convert string to bool
26
+ icinga_cluster = icinga_cluster.to_s.eql?('true') ? true : false
27
+
28
+ config = {
29
+ icinga: {
30
+ host: icinga_host,
31
+ api: {
32
+ port: icinga_api_port,
33
+ user: icinga_api_user,
34
+ password: icinga_api_pass,
35
+ pki_path: icinga_api_pki_path,
36
+ node_name: icinga_api_node_name
37
+ },
38
+ cluster: icinga_cluster,
39
+ satellite: icinga_satellite
40
+ }
41
+ }
42
+
43
+ # ---------------------------------------------------------------------------------------
44
+
45
+ i = Icinga2::Client.new( config )
46
+
47
+ unless( i.nil? )
48
+
49
+ # run tests ...
50
+ #
51
+ #
52
+
53
+ begin
54
+
55
+ puts ' ------------------------------------------------------------- '
56
+ puts ''
57
+
58
+
59
+
60
+ puts ' ------------------------------------------------------------- '
61
+ puts ''
62
+
63
+ rescue => e
64
+ $stderr.puts( e )
65
+ $stderr.puts( e.backtrace.join("\n") )
66
+ end
67
+ end
68
+
69
+
70
+ # -----------------------------------------------------------------------------
71
+
72
+ # EOF
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # 07.10.2017 - Bodo Schulz
5
+ #
6
+ #
7
+ # Examples for Hostgroups
8
+
9
+ # -----------------------------------------------------------------------------
10
+
11
+ require_relative '../lib/icinga2'
12
+
13
+ # -----------------------------------------------------------------------------
14
+
15
+ icinga_host = ENV.fetch( 'ICINGA_HOST' , 'icinga2' )
16
+ icinga_api_port = ENV.fetch( 'ICINGA_API_PORT' , 5665 )
17
+ icinga_api_user = ENV.fetch( 'ICINGA_API_USER' , 'admin' )
18
+ icinga_api_pass = ENV.fetch( 'ICINGA_API_PASSWORD' , nil )
19
+ icinga_api_pki_path = ENV.fetch( 'ICINGA_API_PKI_PATH' , '/etc/icinga2' )
20
+ icinga_api_node_name = ENV.fetch( 'ICINGA_API_NODE_NAME' , nil )
21
+ icinga_cluster = ENV.fetch( 'ICINGA_CLUSTER' , false )
22
+ icinga_satellite = ENV.fetch( 'ICINGA_CLUSTER_SATELLITE', nil )
23
+
24
+
25
+ # convert string to bool
26
+ icinga_cluster = icinga_cluster.to_s.eql?('true') ? true : false
27
+
28
+ config = {
29
+ icinga: {
30
+ host: icinga_host,
31
+ api: {
32
+ port: icinga_api_port,
33
+ user: icinga_api_user,
34
+ password: icinga_api_pass,
35
+ pki_path: icinga_api_pki_path,
36
+ node_name: icinga_api_node_name
37
+ },
38
+ cluster: icinga_cluster,
39
+ satellite: icinga_satellite
40
+ }
41
+ }
42
+
43
+ # ---------------------------------------------------------------------------------------
44
+
45
+ i = Icinga2::Client.new( config )
46
+
47
+ unless( i.nil? )
48
+
49
+ # run tests ...
50
+ #
51
+ #
52
+
53
+ begin
54
+
55
+ puts ' ------------------------------------------------------------- '
56
+ puts ''
57
+
58
+ # puts ' ==> DOWNTIMES'
59
+ # puts ''
60
+ # puts 'add Downtime \'test\''
61
+ # puts i.add_downtime( name: 'test', type: 'service', host: 'foo', comment: 'test downtime', author: 'icingaadmin', start_time: Time.now.to_i, end_time: Time.now.to_i + 20 )
62
+ # puts ''
63
+ # puts 'list all Downtimes'
64
+ # puts i.downtimes
65
+ # puts ''
66
+
67
+ puts ' ------------------------------------------------------------- '
68
+ puts ''
69
+
70
+ rescue => e
71
+ $stderr.puts( e )
72
+ $stderr.puts( e.backtrace.join("\n") )
73
+ end
74
+ end
75
+
76
+
77
+ # -----------------------------------------------------------------------------
78
+
79
+ # EOF
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # 07.10.2017 - Bodo Schulz
5
+ #
6
+ #
7
+ # Examples for Hostgroups
8
+
9
+ # -----------------------------------------------------------------------------
10
+
11
+ require_relative '../lib/icinga2'
12
+
13
+ # -----------------------------------------------------------------------------
14
+
15
+ icinga_host = ENV.fetch( 'ICINGA_HOST' , 'icinga2' )
16
+ icinga_api_port = ENV.fetch( 'ICINGA_API_PORT' , 5665 )
17
+ icinga_api_user = ENV.fetch( 'ICINGA_API_USER' , 'admin' )
18
+ icinga_api_pass = ENV.fetch( 'ICINGA_API_PASSWORD' , nil )
19
+ icinga_api_pki_path = ENV.fetch( 'ICINGA_API_PKI_PATH' , '/etc/icinga2' )
20
+ icinga_api_node_name = ENV.fetch( 'ICINGA_API_NODE_NAME' , nil )
21
+ icinga_cluster = ENV.fetch( 'ICINGA_CLUSTER' , false )
22
+ icinga_satellite = ENV.fetch( 'ICINGA_CLUSTER_SATELLITE', nil )
23
+
24
+
25
+ # convert string to bool
26
+ icinga_cluster = icinga_cluster.to_s.eql?('true') ? true : false
27
+
28
+ config = {
29
+ icinga: {
30
+ host: icinga_host,
31
+ api: {
32
+ port: icinga_api_port,
33
+ user: icinga_api_user,
34
+ password: icinga_api_pass,
35
+ pki_path: icinga_api_pki_path,
36
+ node_name: icinga_api_node_name
37
+ },
38
+ cluster: icinga_cluster,
39
+ satellite: icinga_satellite
40
+ }
41
+ }
42
+
43
+ # ---------------------------------------------------------------------------------------
44
+
45
+ i = Icinga2::Client.new( config )
46
+
47
+ unless( i.nil? )
48
+
49
+ # run tests ...
50
+ #
51
+ #
52
+
53
+ begin
54
+
55
+ puts ' ------------------------------------------------------------- '
56
+ puts ''
57
+
58
+ puts '= check if Hostgroup \'linux-servers\' exists'
59
+ puts i.exists_hostgroup?( 'linux-servers' ) ? 'true' : 'false'
60
+ puts ''
61
+ puts '= check if Hostgroup \'docker\' exists'
62
+ puts i.exists_hostgroup?( 'docker' ) ? 'true' : 'false'
63
+ puts ''
64
+ puts '= list named Hostgroup \'linux-servers\''
65
+ puts i.hostgroups( host_group: 'linux-servers' )
66
+ puts ''
67
+ puts '= list named Hostgroup \'foo\''
68
+ puts i.hostgroups( host_group: 'foo' )
69
+ puts ''
70
+ puts '= list all Hostgroups'
71
+ puts i.hostgroups
72
+ puts ''
73
+ puts '= add hostgroup \'foo\''
74
+ puts i.add_hostgroup( host_group: 'foo', display_name: 'FOO' )
75
+ puts ''
76
+ puts '= delete Hostgroup \'foo\''
77
+ puts i.delete_hostgroup( host_group: 'foo' )
78
+
79
+ puts ' ------------------------------------------------------------- '
80
+ puts ''
81
+
82
+ rescue => e
83
+ $stderr.puts( e )
84
+ $stderr.puts( e.backtrace.join("\n") )
85
+ end
86
+ end
87
+
88
+
89
+ # -----------------------------------------------------------------------------
90
+
91
+ # EOF