<s> from collections import defaultdict <EOL> import sysctl <EOL> from django . utils . translation import ugettext as _ <EOL> from freenasUI . system . alert import alertPlugins , Alert , BaseAlert <EOL> class MPSFirmwareAlert ( BaseAlert ) : <EOL> def run ( self ) : <EOL> alerts = [ ] <EOL> mps = defaultdict ( dict ) <EOL> for o in sysctl . filter ( '<STR_LIT>' ) : <EOL> mibs = o . name . split ( '<STR_LIT:.>' , <NUM_LIT:3> ) <EOL> if len ( mibs ) < <NUM_LIT:4> : <EOL> continue <EOL> number , mib = mibs [ <NUM_LIT:2> : <NUM_LIT:4> ] <EOL> try : <EOL> major = int ( o . value . split ( '<STR_LIT:.>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] ) <EOL> mps [ number ] [ mib ] = major <EOL> except : <EOL> continue <EOL> for number , mibs in mps . items ( ) : <EOL> firmware = mibs . get ( '<STR_LIT>' ) <EOL> driver = mibs . get ( '<STR_LIT>' ) <EOL> try : <EOL> if int ( firmware ) != int ( driver ) : <EOL> alerts . append ( Alert ( <EOL> Alert . WARN , <EOL> _ ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) % { <EOL> '<STR_LIT>' : firmware , <EOL> '<STR_LIT>' : driver , <EOL> '<STR_LIT>' : number , <EOL> } <EOL> ) ) <EOL> except ValueError : <EOL> if firmware != driver : <EOL> alerts . append ( Alert ( <EOL> Alert . WARN , <EOL> _ ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) % { <EOL> '<STR_LIT>' : firmware , <EOL> '<STR_LIT>' : driver , <EOL> '<STR_LIT>' : number , <EOL> } <EOL> ) ) <EOL> return alerts <EOL> alertPlugins . register ( MPSFirmwareAlert ) </s>
