Skip to content

Commit

Permalink
Add support for export of downtimes (#6)
Browse files Browse the repository at this point in the history
We need to be able to export downtimes
  • Loading branch information
mickenordin authored and theseal committed Mar 26, 2018
1 parent 3f8fc33 commit 7c840d1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 14 additions & 1 deletion lib/Monitoring/Icinga2/Client/REST.pm
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ sub _encode_param {
[ qw/ arguments command env vars timeout / ],
[ qw/ templates zone / ],
],
Downtime => [
[ qw/ author comment duration end_time entry_time fixed
host_name service_name start_time triggers /
],
[ qw/ templates zone / ],
],
Host => [
[ qw/ address6 address check_command display_name event_command
action_url notes notes_url vars icon_image icon_image_alt
Expand All @@ -127,6 +133,12 @@ sub _encode_param {
[ qw/ action_url display_name notes notes_url vars / ],
[ qw/ groups templates zone / ],
],
ScheduledDowntime => [
[ qw/ author comment duration fixed host_name ranges
service_name /
],
[ qw/ templates zone / ],
],
Service => [
[ qw/ vars action_url check_command check_interval display_name
notes notes_url event_command max_check_attempts
Expand Down Expand Up @@ -164,7 +176,8 @@ sub _encode_param {
my ( $self, $full, $api_only ) = @_;
my $result = decode_json( encode_utf8( $self->{res}->content ) );
my $type = $result->{results}[0]{type};

# Do nothing if there is nothing to export
return unless $type;
# We only support certain object types
return unless exists $type2keys{$type};

Expand Down
8 changes: 4 additions & 4 deletions lib/Monitoring/Icinga2/Client/REST.pod
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ Monitoring::Icinga2::Client::REST - REST integration with icinga2
};


my $put_result = $icinga->do_request("PUT", "/objects/hosts/localhost.example.com", "", $host_object);
my $put_result = $icinga->do_request("PUT", "/objects/hosts/localhost.example.com", "", $host_object)
or warn sprintf("%s: %s", $icinga->request_code, $icinga->request_status_line);

my $post_result = $icinga->do_request("POST", "/objects/hosts/localhost.example.com", "",$host_object);
my $post_result = $icinga->do_request("POST", "/objects/hosts/localhost.example.com", "",$host_object)
or warn sprintf("%s: %s", $icinga->request_code, $icinga->request_status_line);

my $get_result = $icinga->do_request("GET", "/objects/hosts/localhost.example.com");
my $get_result = $icinga->do_request("GET", "/objects/hosts/localhost.example.com")
or warn sprintf("%s: %s", $icinga->request_code, $icinga->request_status_line);

my $delete_result = $icinga->do_request("DELETE", "/objects/hosts/localhost.example.com");
my $delete_result = $icinga->do_request("DELETE", "/objects/hosts/localhost.example.com")
or warn sprintf("%s: %s", $icinga->request_code, $icinga->request_status_line);

$icinga->logout;
Expand Down

0 comments on commit 7c840d1

Please sign in to comment.