ManageIQ / manageiq-providers-cisco_intersight

ManageIQ provider for Cisco Intersight
Apache License 2.0
2 stars 15 forks source link

Event catcher for Cisco Intersight provider #55

Closed gberginc closed 2 years ago

gberginc commented 2 years ago

This PR introduces an event catcher for Cisco Intersight provider.

Currently it is collecting Alarms only. A separate API call might be used to also collect some other information, but the logic will be very similar.

gberginc commented 2 years ago

@agrare This is the initial implementation of the event catcher for Intersight provider. The events are collected and pushed to DB with the parsed data:

2.7.2 :001 > pp EventStream.find(55)
PostgreSQLAdapter#log_after_checkout, connection_pool: size: 5, connections: 1, in use: 1, waiting_in_queue: 0
  EventStream Load (6.9ms)  SELECT "event_streams".* FROM "event_streams" WHERE "event_streams"."id" = $1 LIMIT $2  [["id", 55], ["LIMIT", 1]]
  EventStream Inst Including Associations (1643.8ms - 1rows)
#<EmsEvent:0x00007fbb6a41f730
 id: 55,
 event_type: "Info",
 message:
  "Port LAB02D02F01/switch-A/slot-1/ethport-50 has no transceiver inserted",
 timestamp: Wed, 23 Feb 2022 04:39:33 UTC +00:00,

However, I can't seem to understand how to show them in the Timelines UI:

Screenshot 2022-05-06 at 22 07 41

Is there any config missing? As the event is from February 23, I think the date filter in the UI should be fine.

Fryguy commented 2 years ago

@gberginc You will need add config in the event_groups section of your settings.yml to show things on the timeline. See the event_groups section in the core repo or a provider specific one that uses regexes in the redfish repo.

It's hard to tell but it is organized in sections and then criticality which corresponds to the dropdowns you can choose in the UI for filtering.

Hope that helps.

Fryguy commented 2 years ago

I noticed your event_type is "Info", which is going to be really difficult to present properly as it's very generic. Is it possible to have a more "detailed" event type name?

gberginc commented 2 years ago

That's awesome, @Fryguy, THANKS!

You are correct regarding event_type, we were using wrong info. I'll push a change that uses the actual name of the event.

After adding the config for an alarm, I was able to see it in the timeline.

Screenshot 2022-05-07 at 12 49 43
gberginc commented 2 years ago

Still, I am not sure all is fine. I now have an alarm with the event_type = alarm_EtherTransceiverNotPresent.

However, if I have this in config, I will not see it in the timeline:

:ems:
  :ems_cisco_intersight:
    :blacklisted_event_names: []
    :event_handling:
      :event_groups:
        :general:
          :critical:
          - /^alarm_/

If I change the last line to have a complete event name, it works as shown in the screenshot before.

:ems:
  :ems_cisco_intersight:
    :blacklisted_event_names: []
    :event_handling:
      :event_groups:
        :general:
          :critical:
          - alarm_EtherTransceiverNotPresent

I have also tried with /^alarm_.*/ but also did not get it.

gberginc commented 2 years ago

Really odd as spec/lib/manageiq/reporting/formatter/timeline_spec.rb passed all tests when I changed the test to use alarm_ prefix.

gberginc commented 2 years ago

Also looking at this change that introduced regular expressions and the associated spec, I am able to pass all of them if I use my /^alarm_/ regex.

On the other hand, when I checked the actual SQL statement being requested in PG, I got the following (truncated for readability):

SELECT 
    "event_streams"."id" AS t0_r0, "event_streams"."event_type" AS t0_r1, 
    "event_streams"."message" AS t0_r2, "event_streams"."timestamp" AS t0_r3, ...
WHERE 
    ((event_streams.ems_id = 2) 
     and (timestamp >= '2021-12-02 00:00:00') and (timestamp <= '2022-04-30 23:59:59') 
     and ((event_type in 'AD_COMPUTER_ACCOUNT_FAILED','AD_COMPUTER_ACCOUNT_SUCCEEDED', '/^alarm_/'))));

This obviously does not return a record as it's not really matching on regex (I think).

Could it be that there was a change in how we are retrieving events from the database and since the above spec does not check (again, I think) actual DB, it passes?

ghost commented 2 years ago

@agrare, do you have any suggestions how to reformat this code: https://github.com/tjazsch/manageiq-providers-cisco_intersight/blob/c63d19ca73a7586c98b308ec9803645e0590f671/app/models/manageiq/providers/cisco_intersight/physical_infra_manager/event_catcher/stream.rb#L39-L40 according to the miq-bot standards?

agrare commented 2 years ago

@tjazsch yes what rubocop is suggesting is:

def poll(&block)
  ...
  events.each(&block)
  workflow_infos.each(&block)
ghost commented 2 years ago

Thanks a lot!

miq-bot commented 2 years ago

Checked commits https://github.com/tjazsch/manageiq-providers-cisco_intersight/compare/e85dd7440440264d58bed273bd38cc8834910d94~...4b93ca66016e6a99e5ca70424c325c404e8bb4bf with ruby 2.6.9, rubocop 1.19.1, haml-lint 0.35.0, and yamllint 6 files checked, 0 offenses detected Everything looks fine. :+1: