@@ -79,7 +79,7 @@ def msg_curse(self, args=None, max_width=None):
79
79
if max_width :
80
80
name_max_width = max_width - 12
81
81
else :
82
- # No max_width defined, return an emptu curse message
82
+ # No max_width defined, return an empty curse message
83
83
logger .debug (f"No max_width defined for the { self .plugin_name } plugin, it will not be displayed." )
84
84
return ret
85
85
@@ -93,68 +93,76 @@ def msg_curse(self, args=None, max_width=None):
93
93
# Data
94
94
arrays = sorted (iterkeys (self .stats ))
95
95
for array in arrays :
96
- # New line
97
- ret .append (self .curse_new_line ())
98
- # Display the current status
99
- if not isinstance (self .stats [array ], dict ):
96
+ array_stats = self .stats [array ]
97
+
98
+ if not isinstance (array_stats , dict ):
100
99
continue
100
+
101
+ # Display the current status
101
102
status = self .raid_alert (
102
- self . stats [ array ] ['status' ],
103
- self . stats [ array ] ['used' ],
104
- self . stats [ array ] ['available' ],
105
- self . stats [ array ] ['type' ],
103
+ array_stats ['status' ],
104
+ array_stats ['used' ],
105
+ array_stats ['available' ],
106
+ array_stats ['type' ],
106
107
)
108
+
109
+ # New line
110
+ ret .append (self .curse_new_line ())
107
111
# Data: RAID type name | disk used | disk available
108
- array_type = self . stats [ array ][ 'type' ].upper () if self . stats [ array ] ['type' ] is not None else 'UNKNOWN'
112
+ array_type = array_stats [ 'type' ].upper () if array_stats ['type' ] is not None else 'UNKNOWN'
109
113
# Build the full name = array type + array name
110
114
full_name = f'{ array_type } { array } '
111
115
msg = '{:{width}}' .format (full_name , width = name_max_width )
112
116
ret .append (self .curse_add_line (msg ))
113
- if self . stats [ array ][ 'type' ] == 'raid0' and self . stats [ array ] ['status' ] == 'active' :
114
- msg = '{:>7}' .format (len (self . stats [ array ] ['components' ]))
117
+ if array_stats [ 'type' ] == 'raid0' and array_stats ['status' ] == 'active' :
118
+ msg = '{:>7}' .format (len (array_stats ['components' ]))
115
119
ret .append (self .curse_add_line (msg , status ))
116
120
msg = '{:>7}' .format ('-' )
117
121
ret .append (self .curse_add_line (msg , status ))
118
- elif self . stats [ array ] ['status' ] == 'active' :
119
- msg = '{:>7}' .format (self . stats [ array ] ['used' ])
122
+ elif array_stats ['status' ] == 'active' :
123
+ msg = '{:>7}' .format (array_stats ['used' ])
120
124
ret .append (self .curse_add_line (msg , status ))
121
- msg = '{:>7}' .format (self . stats [ array ] ['available' ])
125
+ msg = '{:>7}' .format (array_stats ['available' ])
122
126
ret .append (self .curse_add_line (msg , status ))
123
- elif self . stats [ array ] ['status' ] == 'inactive' :
127
+ elif array_stats ['status' ] == 'inactive' :
124
128
ret .append (self .curse_new_line ())
125
- msg = '└─ Status {}' .format (self . stats [ array ] ['status' ])
129
+ msg = '└─ Status {}' .format (array_stats ['status' ])
126
130
ret .append (self .curse_add_line (msg , status ))
127
- components = sorted (iterkeys (self . stats [ array ] ['components' ]))
131
+ components = sorted (iterkeys (array_stats ['components' ]))
128
132
for i , component in enumerate (components ):
129
133
if i == len (components ) - 1 :
130
134
tree_char = '└─'
131
135
else :
132
136
tree_char = '├─'
133
137
ret .append (self .curse_new_line ())
134
- msg = ' {} disk {}: ' .format (tree_char , self . stats [ array ] ['components' ][component ])
138
+ msg = ' {} disk {}: ' .format (tree_char , array_stats ['components' ][component ])
135
139
ret .append (self .curse_add_line (msg ))
136
140
msg = f'{ component } '
137
141
ret .append (self .curse_add_line (msg ))
138
- if self .stats [array ]['type' ] != 'raid0' and (self .stats [array ]['used' ] < self .stats [array ]['available' ]):
142
+
143
+ if array_stats ['type' ] != 'raid0' and (
144
+ array_stats ['used' ] and array_stats ['available' ] and array_stats ['used' ] < array_stats ['available' ]
145
+ ):
139
146
# Display current array configuration
140
147
ret .append (self .curse_new_line ())
141
148
msg = '└─ Degraded mode'
142
149
ret .append (self .curse_add_line (msg , status ))
143
- if len (self . stats [ array ] ['config' ]) < 17 :
150
+ if len (array_stats ['config' ]) < 17 :
144
151
ret .append (self .curse_new_line ())
145
- msg = ' └─ {}' .format (self . stats [ array ] ['config' ].replace ('_' , 'A' ))
152
+ msg = ' └─ {}' .format (array_stats ['config' ].replace ('_' , 'A' ))
146
153
ret .append (self .curse_add_line (msg ))
147
154
148
155
return ret
149
156
150
- def raid_alert (self , status , used , available , type ):
157
+ @staticmethod
158
+ def raid_alert (status , used , available , raid_type ) -> str :
151
159
"""RAID alert messages.
152
160
153
161
[available/used] means that ideally the array may have _available_
154
162
devices however, _used_ devices are in use.
155
163
Obviously when used >= available then things are good.
156
164
"""
157
- if type == 'raid0' :
165
+ if raid_type == 'raid0' :
158
166
return 'OK'
159
167
if status == 'inactive' :
160
168
return 'CRITICAL'
0 commit comments