@@ -48,19 +48,61 @@ def process_alert_info(self, alert):
4848 alert )
4949 # Fill storage specific info
5050 if alert_model :
51+ storage = self .get_storage_from_parsed_alert (
52+ ctxt , storage , alert_model )
5153 alert_util .fill_storage_attributes (alert_model , storage )
5254 except exception .IncompleteTrapInformation as e :
5355 LOG .warn (e )
5456 threading .Thread (target = self .sync_storage_alert ,
5557 args = (ctxt , alert ['storage_id' ])).start ()
58+ except exception .AlertSourceNotFound :
59+ LOG .info ("Could not identify alert source from parsed alert. "
60+ "Skipping the dispatch of alert" )
61+ return
5662 except Exception as e :
5763 LOG .error (e )
5864 raise exception .InvalidResults (
5965 "Failed to fill the alert model from driver." )
6066
6167 # Export to base exporter which handles dispatch for all exporters
6268 if alert_model :
63- self .exporter_manager .dispatch (ctxt , alert_model )
69+ LOG .info ("Dispatching one SNMP Trap to {} with sn {}" .format (
70+ alert_model ['storage_id' ], alert_model ['serial_number' ]))
71+ self .exporter_manager .dispatch (ctxt , [alert_model ])
72+
73+ def get_storage_from_parsed_alert (self , ctxt , storage , alert_model ):
74+ # If parse_alert sets 'serial_number' or 'storage_name' in the
75+ # alert_model, we need to get corresponding storage details
76+ # from the db and fill that in alert_model
77+ storage_sn = alert_model .get ('serial_number' )
78+ storage_name = alert_model .get ('storage_name' )
79+ filters = {
80+ "vendor" : storage ['vendor' ],
81+ "model" : storage ['model' ],
82+ }
83+ try :
84+ if storage_sn and storage_sn != storage ['serial_number' ]:
85+ filters ['serial_number' ] = storage_sn
86+ elif storage_name and storage_name != storage ['name' ]:
87+ filters ['name' ] = storage_name
88+ else :
89+ return storage
90+
91+ storage_list = db .storage_get_all (ctxt , filters = filters )
92+ if not storage_list :
93+ msg = "Failed to get destination storage for SNMP Trap. " \
94+ "Storage with serial number {} or storage name {} " \
95+ "not found in DB" .format (storage_sn , storage_name )
96+ raise exception .AlertSourceNotFound (msg )
97+ db .alert_source_get (ctxt , storage_list [0 ]['id' ])
98+ storage = storage_list [0 ]
99+ except exception .AlertSourceNotFound :
100+ LOG .info ("Storage with serial number {} or name {} "
101+ "is not registered for receiving "
102+ "SNMP Trap" .format (storage_sn , storage_name ))
103+ raise
104+
105+ return storage
64106
65107 @coordination .synchronized ('sync-trap-{storage_id}' , blocking = False )
66108 def sync_storage_alert (self , context , storage_id ):
0 commit comments