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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/icinga2/downtimes.rb', line 35 def add_downtime( params ) raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) ) raise ArgumentError.new('missing \'params\'') if( params.size.zero? ) name = params.dig(:name) host_name = params.dig(:host_name) 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) fixed = params.dig(:fixed) || true duration = params.dig(:duration) || 30 entry_time = params.dig(:entry_time) scheduled_by = params.dig(:scheduled_by) service_name = params.dig(:service_name) triggered_by = params.dig(:triggered_by) config_owner = params.dig(:config_owner) 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 are 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 ) raise ArgumentError.new(format('wrong type. \'duration\' must be Integer, given \'%s\'', duration.class.to_s)) unless( duration.is_a?(Integer) ) raise ArgumentError.new(format('wrong type. \'fixed\' must be True or False, given \'%s\'', fixed.class.to_s)) unless( fixed.is_a?(TrueClass) || fixed.is_a?(FalseClass) ) # TODO # check if host_name exists! 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: fixed, duration: duration, filter: filter, entry_time: entry_time, scheduled_by: scheduled_by, host_name: host_name, host_group: host_group, service_name: service_name, triggered_by: triggered_by, config_owner: config_owner } # remove all empty attrs payload.reject!{ |_k, v| v.nil? } post( url: format( '%s/actions/schedule-downtime', @icinga_api_url_base ), headers: @headers, options: @options, payload: payload ) end |
#downtimes ⇒ Array
return downtimes
121 122 123 124 125 126 127 128 |
# File 'lib/icinga2/downtimes.rb', line 121 def downtimes api_data( url: format( '%s/objects/downtimes' , @icinga_api_url_base ), headers: @headers, options: @options ) end |