Module: Xcal::Parktronic::Routes
- Includes:
- Alarms, CommandNotifications, CustomQueries, DataCenterServiceStates, EventHistoryItems, Events, Metrics, Outages, StackChanges
- Included in:
- ApiClient
- Defined in:
- lib/xcal/parktronic/routes.rb,
lib/xcal/parktronic/routes/alarms.rb,
lib/xcal/parktronic/routes/events.rb,
lib/xcal/parktronic/routes/metrics.rb,
lib/xcal/parktronic/routes/outages.rb,
lib/xcal/parktronic/routes/nested/events.rb,
lib/xcal/parktronic/routes/stack_changes.rb,
lib/xcal/parktronic/routes/custom_queries.rb,
lib/xcal/parktronic/routes/event_history_items.rb,
lib/xcal/parktronic/routes/nested/value_groups.rb,
lib/xcal/parktronic/routes/nested/alarm_actions.rb,
lib/xcal/parktronic/routes/nested/metric_values.rb,
lib/xcal/parktronic/routes/command_notifications.rb,
lib/xcal/parktronic/routes/data_center_service_states.rb
Defined Under Namespace
Modules: Alarms, CommandNotifications, CustomQueries, DataCenterServiceStates, EventHistoryItems, Events, Metrics, Nested, Outages, StackChanges
Instance Method Summary collapse
-
#get_alarm_tags(id) ⇒ Object
(also: #alarm_tags)
Find all Alarm Tags.
-
#search_alarm(args = {}) ⇒ Object
Search unclosed alarm by name or tag or originating system with time range.
Methods included from DataCenterServiceStates
#get_data_center_service_states
Methods included from CustomQueries
#find_custom_query, #get_custom_queries, #post_custom_query, #update_custom_query
Methods included from CommandNotifications
#get_paged_command_notifications, #update_command_notification
Methods included from EventHistoryItems
#get_paged_event_history_items
Methods included from StackChanges
#get_paged_stack_changes, #post_stack_change
Methods included from Outages
Methods included from Events
#get_event, #get_event_tags, #update_event
Methods included from Metrics
#get_metric, #get_metric_by_name, #get_paged_metrics, #post_metric, #update_metric
Methods included from Alarms
#get_alarm, #get_paged_alarms, #post_alarm, #update_alarm
Instance Method Details
#get_alarm_tags(id) ⇒ Object Also known as:
Find all Alarm Tags
Parameters
-
id
alarm ID
Examples
api.(2)
api.(2)
98 99 100 101 102 103 |
# File 'lib/xcal/parktronic/routes/alarms.rb', line 98 def (id) response = get_response("/#{api_version}/alarms/#{id}/tags?#{URI.encode_www_form(access_token: access_token)}") generic_response = Xcal::Parktronic::GenericResponse.new(response.body, self) response.code == '200' && generic_response.has_key?(:tags) ? generic_response..map(&:tag) : generic_response end |
#search_alarm(args = {}) ⇒ Object
Search unclosed alarm by name or tag or originating system with time range
Parameters
-
name
string, alarm name -
tagged_with
string or array, tag list -
time_range
integer, time range in hours, defaults to 24 hours -
originating_system
string or array, originating system name(s), blank by default (example: ‘Op5_Nagios’ or ‘Op5_Nagios Splunk’ or [‘Op5_Nagios’, ‘Splunk’]) -
page
integer, page number, defaults to 1 -
per_page
integer, per page value, defaults to 100 -
where
‘where’ hash of conditions for searching -
extends
array, may include: latest_event, latest_unclosed_event, with_unclosed_events, with_most_recent_events, top_alarms, select_brouha_open
Examples
api.search_alarm(name: 'test alarm')
api.search_alarm(tagged_with: 'test alarm', time_range: 120)
api.search_alarm(where: {impact_level: 'Unknown', originating_system: 'test'}, time_range: 120)
api.search_alarm(extends: ['latest_event', 'with_most_recent_events'], time_range: 120)
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/xcal/parktronic/routes/alarms.rb', line 123 def search_alarm(args = {}) custom_scopes = { with_most_recent_events: [] } #Filter filter = { alarms: '' } custom_filter = args[:originating_system] custom_filter = custom_filter.split(' ') if custom_filter.is_a?(String) filter = { alarms: custom_filter.map{|os| "originating_system = '#{os}'"}.join(' OR ') } unless custom_filter.nil? #Scopes (time range) custom_scopes[:within_event_date_range] = [(Time.now - (60 * (60 * args.fetch(:time_range, 24)))).strftime('%Y-%m-%d %H:%M:%S'), Time.now.strftime('%Y-%m-%d %H:%M:%S')] #Tags custom_scopes[:tagged_with] = args[:tagged_with] unless args[:tagged_with].nil? # Params for request scopes = URI.escape(custom_scopes.to_json) search = URI.escape({name: args.fetch(:name, '')}.to_json) extends = URI.escape(args.fetch(:extends, []).to_json) filter = URI.escape(args.fetch(:filter, filter).to_json) where = URI.escape(args.fetch(:where, '').to_json) page = args.fetch(:page, 1) per_page = args.fetch(:per_page, 100) response = get_response("/#{api_version}/alarms/search?page=#{page}&per_page=#{per_page}&scopes=#{scopes}&search=#{search}&extends=#{extends}&filter=#{filter}&where=#{where}&access_token=#{access_token}") generic_response = Xcal::Parktronic::GenericResponse.new(response.body) response.code == '200' && generic_response.has_key?(:alarms) ? generic_response.alarms.map(&:alarm) : generic_response end |