@@ -595,3 +595,266 @@ def cli(self, output=None):
595595 continue
596596
597597 return ret_dict
598+
599+ class ShowEnvironmentAllSchema (MetaParser ):
600+ """Schema for show environment all
601+ show environment all | include {include} """
602+
603+ schema = {
604+ Optional ('critical_alarms' ): int ,
605+ Optional ('major_alarms' ): int ,
606+ Optional ('minor_alarms' ): int ,
607+ 'sensor_list' : {
608+ Any (): {
609+ 'slot' : {
610+ Any (): {
611+ 'sensor' : {
612+ Any (): {
613+ 'state' : str ,
614+ 'reading' : str ,
615+ Optional ('threshold' ): {
616+ 'minor' : int ,
617+ 'major' : int ,
618+ 'critical' : int ,
619+ 'shutdown' : int ,
620+ 'unit' : str ,
621+ }
622+ }
623+ }
624+ }
625+ }
626+ }
627+ },
628+ 'switch' : {
629+ Any (): {
630+ 'power_supply' : {
631+ 'slot' : {
632+ Any (): {
633+ 'model_no' : str ,
634+ 'type' : str ,
635+ 'capacity' : str ,
636+ 'status' : str ,
637+ 'fan_1_state' : str ,
638+ 'fan_2_state' : str ,
639+ }
640+ },
641+ 'current_configuration_mode' : str ,
642+ 'current_operating_state' : str ,
643+ 'currently_active' : int ,
644+ 'currently_available' : int ,
645+ },
646+ 'fantray' : {
647+ 'status' : str ,
648+ 'power_consumed_by_fantray_watts' : int ,
649+ 'fantray_airflow_direction' : str ,
650+ 'fantray_beacon_led' : str ,
651+ 'fantray_status_led' : str ,
652+ 'system' : str ,
653+ },
654+ },
655+ },
656+ }
657+
658+
659+ class ShowEnvironmentAll (ShowEnvironmentAllSchema ):
660+ """Parser for show environment all
661+ show environment all | include {include}"""
662+
663+ cli_command = [
664+ 'show environment all' , 'show environment all | include {include}'
665+ ]
666+
667+ def cli (self , include = '' , output = None ):
668+ if not output :
669+ if include :
670+ cmd = self .cli_command [1 ].format (include = include )
671+ else :
672+ cmd = self .cli_command [0 ]
673+ output = self .device .execute (cmd )
674+
675+ # initial return dictionary
676+ ret_dict = {}
677+
678+ # Number of Critical alarms: 0
679+ p1 = re .compile (
680+ r'^Number +of +Critical +alarms: +(?P<critic_alarms>\d+)$' )
681+
682+ # Number of Major alarms: 0
683+ p2 = re .compile (r'^Number +of +Major +alarms: +(?P<maj_alarms>\d+)$' )
684+
685+ # Number of Minor alarms: 0
686+ p3 = re .compile (r'^Number +of +Minor +alarms: +(?P<min_alarms>\d+)$' )
687+
688+ # Sensor List: Environmental Monitoring
689+ p4 = re .compile (r'Sensor\s+List:\s+(?P<sensor_list>.+)' )
690+
691+ # Sensor Location State Reading Threshold(Minor,Major,Critical,Shutdown)
692+ # Temp: Coretemp Chassis1-R0 Normal 46 Celsius (107,117,123,125)(Celsius)
693+ # Temp: UADP Chassis1-R0 Normal 54 Celsius (107,117,123,125)(Celsius)
694+ # V1: VX1 Chassis1-R0 Normal 871 mV na
695+ # V1: VX2 Chassis1-R0 Normal 1498 mV na
696+ # V1: VX3 Chassis1-R0 Normal 1055 mV na
697+ # V1: VX4 Chassis1-R0 Normal 852 mV na
698+ # V1: VX5 Chassis1-R0 Normal 1507 mV na
699+ # V1: VX6 Chassis1-R0 Normal 1301 mV na
700+ # V1: VX7 Chassis1-R0 Normal 1005 mV na
701+ p5 = re .compile (
702+ r'(?P<sensor_name>\S+(:\s+\S+)?)\s+(?P<slot>\S+[0-9])\s+(?P<state>\S+)\s+(?P<reading>\d+\s+\S+(\s+(AC|DC))?)\s+(\((?P<minor>\d+\s*),(?P<major>\d+\s*),(?P<critical>\d+\s*),(?P<shutdown>\d+\s*)\)\((?P<unit>\S+)\))?'
703+ )
704+
705+ # Switch:1
706+ p6 = re .compile (r'^Switch:(?P<switch>\d+)' )
707+
708+ # Power Fan States
709+ # Supply Model No Type Capacity Status 1 2
710+ # ------ -------------------- ---- -------- ------------ -----------
711+ # PS1 C9400-PWR-3200AC ac 3200 W active good good
712+ # PS2 C9400-PWR-3200AC ac n.a. faulty good good
713+ p7 = re .compile (
714+ r'(?P<ps_slot>PS\S+)\s+(?P<model_no>\S+)\s+(?P<type>\S+)\s+(?P<capacity>\S+(\s+\S+)?)\s+(?P<status>\S+)\s+(?P<fan_1_state>\S+)\s+(?P<fan_2_state>\S+)$'
715+ )
716+
717+ # PS Current Configuration Mode : Combined
718+ # PS Current Operating State : Combined
719+ # Power supplies currently active : 1
720+ # Power supplies currently available : 1
721+ p8 = re .compile (
722+ r'(PS|Power supplies)\s+(?P<ps_key>.+)\s+:\s+(?P<ps_value>\S+)' )
723+
724+ # Switch 1:
725+ p9 = re .compile (r'^Switch +(?P<switch>\d+)' )
726+
727+ # Fantray : good
728+ # Power consumed by Fantray : 540 Watts
729+ # Fantray airflow direction : side-to-side
730+ # Fantray beacon LED: off
731+ # Fantray status LED: green
732+ # SYSTEM : GREEN
733+ p10 = re .compile (
734+ r'(?P<fantray_key>((.+)?Fantray(.+)?)|SYSTEM)(\s+)?:\s+(?P<fantray_value>(\S+)|(\d+\s+Watts))'
735+ )
736+
737+ for line in output .splitlines ():
738+ line = line .strip ()
739+
740+ # Number of Critical alarms: 0
741+ m = p1 .match (line )
742+ if m :
743+ group = m .groupdict ()
744+ ret_dict ['critical_alarms' ] = int (group ['critic_alarms' ])
745+ continue
746+
747+ # Number of Major alarms: 0
748+ m = p2 .match (line )
749+ if m :
750+ group = m .groupdict ()
751+ ret_dict ['major_alarms' ] = int (group ['maj_alarms' ])
752+ continue
753+
754+ # Number of Minor alarms: 0
755+ m = p3 .match (line )
756+ if m :
757+ group = m .groupdict ()
758+ ret_dict ['minor_alarms' ] = int (group ['min_alarms' ])
759+ continue
760+
761+ # Sensor List: Environmental Monitoring
762+ m = p4 .match (line )
763+ if m :
764+ group = m .groupdict ()
765+ sensor_dict = ret_dict .setdefault ('sensor_list' ,
766+ {}).setdefault (
767+ group ['sensor_list' ], {})
768+ continue
769+
770+ # Sensor Location State Reading Threshold(Minor,Major,Critical,Shutdown)
771+ # Temp: Coretemp R0 Normal 48 Celsius (107,117,123,125)(Celsius)
772+ # Temp: UADP R0 Normal 56 Celsius (107,117,123,125)(Celsius)
773+ # V1: VX1 R0 Normal 869 mV na
774+ # Temp: inlet R0 Normal 32 Celsius (56 ,66 ,96 ,98 )(Celsius)
775+ m = p5 .match (line )
776+ if m :
777+ group = m .groupdict ()
778+ sensor_name = group .pop ('sensor_name' )
779+ slot = group .pop ('slot' )
780+ fin_dict = sensor_dict .setdefault ('slot' , {}).setdefault (slot , {}).\
781+ setdefault ('sensor' , {}).setdefault (sensor_name , {})
782+
783+ fin_dict ['state' ] = group ['state' ]
784+ fin_dict ['reading' ] = group ['reading' ]
785+ if group ['minor' ]:
786+ fin_dict .setdefault ('threshold' , {})
787+ for key in [
788+ 'minor' , 'major' , 'critical' , 'shutdown' , 'unit'
789+ ]:
790+ fin_dict ['threshold' ][key ] = int (
791+ group [key ]) if key != 'unit' else group [key ]
792+ continue
793+
794+ # Switch:1
795+ m = p6 .match (line )
796+ if m :
797+ group = m .groupdict ()
798+ switch = group ['switch' ]
799+ sw_dict = ret_dict .setdefault ('switch' , {}).setdefault (switch , {})
800+
801+ # Power Fan States
802+ # Supply Model No Type Capacity Status 1 2
803+ # ------ -------------------- ---- -------- ------------ -----------
804+ # PS1 C9400-PWR-3200AC ac 3200 W active good good
805+ # PS2 C9400-PWR-3200AC ac n.a. faulty good good
806+ m = p7 .match (line )
807+ if m :
808+ group = m .groupdict ()
809+ ps_slot = group .pop ('ps_slot' )
810+ ps_dict = sw_dict .setdefault ('power_supply' , {})
811+ ps_slot_dict = ps_dict .setdefault ('slot' ,
812+ {}).setdefault (ps_slot , {})
813+ ps_slot_dict .update ({k : v for k , v in group .items ()})
814+
815+ # PS Current Configuration Mode : Combined
816+ # PS Current Operating State : Combined
817+ # Power supplies currently active : 1
818+ # Power supplies currently available : 1
819+ m = p8 .match (line )
820+ if m :
821+ group = m .groupdict ()
822+ ps_key = group ['ps_key' ].strip ().lower ().replace (' ' , '_' )
823+ if 'active' in ps_key or 'available' in ps_key :
824+ ps_value = int (group ['ps_value' ])
825+ else :
826+ ps_value = group ['ps_value' ]
827+ ps_dict .setdefault (ps_key , ps_value )
828+
829+ # Switch 1:
830+ m = p9 .match (line )
831+ if m :
832+ group = m .groupdict ()
833+ switch = group ['switch' ]
834+ sw_dict = ret_dict .setdefault ('switch' , {}).setdefault (switch , {})
835+
836+ # Fantray : good
837+ # Power consumed by Fantray : 540 Watts
838+ # Fantray airflow direction : side-to-side
839+ # Fantray beacon LED: off
840+ # Fantray status LED: green
841+ # SYSTEM : GREEN
842+ m = p10 .match (line )
843+ if m :
844+ group = m .groupdict ()
845+ fantray_key = group ['fantray_key' ].strip ().lower ().replace (
846+ ' ' , '_' )
847+ if 'power_consumed' in fantray_key :
848+ fantray_value = int (group ['fantray_value' ])
849+ fantray_key += '_watts'
850+ else :
851+ fantray_value = group ['fantray_value' ]
852+ if 'fantray' == fantray_key :
853+ sw_dict .setdefault ('fantray' ,
854+ {}).setdefault ('status' , fantray_value )
855+ else :
856+ sw_dict .setdefault ('fantray' ,
857+ {}).setdefault (fantray_key ,
858+ fantray_value )
859+
860+ return ret_dict
0 commit comments