Module: Icinga2::Downtimes
- Included in:
- Client
- Defined in:
- lib/icinga2/downtimes.rb
Overview
namespace for downtimes handling
Instance Method Summary collapse
-
#add_downtime(params) ⇒ Hash
add downtime.
-
#downtimes ⇒ Array
return downtimes.
Instance Method Details
#add_downtime(params) ⇒ Hash
add downtime
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/icinga2/downtimes.rb', line 35 def add_downtime( params ) raise ArgumentError.new('only Hash are allowed') unless( params.is_a?(Hash) ) raise ArgumentError.new('missing params') if( params.size.zero? ) name = params.dig(:name) host_name = params.dig(:host) host_group = params.dig(:host_group) start_time = params.dig(:start_time) || Time.now.to_i end_time = params.dig(:end_time) = params.dig(:author) comment = params.dig(:comment) type = params.dig(:type) filter = nil # sanitychecks # raise ArgumentError.new('Missing name') if( name.nil? ) raise ArgumentError.new("wrong downtype type. only 'host' or' service' allowed ('#{type}' giving)") if( %w[host service].include?(type.downcase) == false ) raise ArgumentError.new('choose host or host_group, not both') if( !host_group.nil? && !host_name.nil? ) raise ArgumentError.new('Missing downtime author') if( .nil? ) raise ArgumentError.new("these author ar not exists: #{}") unless( exists_user?( ) ) raise ArgumentError.new('Missing downtime comment') if( comment.nil? ) raise ArgumentError.new('Missing downtime end_time') if( end_time.nil? ) raise ArgumentError.new('end_time are equal or smaller then start_time') if( end_time.to_i <= start_time ) if( !host_name.nil? ) filter = format( 'host.name=="%s"', host_name ) elsif( !host_group.nil? ) # check if hostgroup available ? # filter = format( '"%s" in host.groups', host_group ) end payload = { 'type' => type.capitalize, # we need the first char as Uppercase 'start_time' => start_time, 'end_time' => end_time, 'author' => , 'comment' => comment, 'fixed' => true, 'duration' => 30, 'filter' => filter } Network.post( url: format( '%s/actions/schedule-downtime', @icinga_api_url_base ), headers: @headers, options: @options, payload: payload ) end |
#downtimes ⇒ Array
return downtimes
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/icinga2/downtimes.rb', line 97 def downtimes data = Network.api_data( url: format( '%s/objects/downtimes' , @icinga_api_url_base ), headers: @headers, options: @options ) return data.dig('results') if( data.dig(:status).nil? ) nil end |