Skip to content

Commit 4a57879

Browse files
authored
Merge pull request #882 from netenglabs/poller-status-normalize
Poller status normalize
2 parents 362bf83 + 746ca48 commit 4a57879

File tree

15 files changed

+37688
-36398
lines changed

15 files changed

+37688
-36398
lines changed

suzieq/config/schema/sqPoller.avsc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
}
2222
},
2323
"display": 4,
24-
"description": "[min, max, avg] of time taken to get data, computed over the greater between the last 5 mins and the polling period"
24+
"description": "[min, max, avg] of time(ms) taken to get data, computed over the greater between the last 5 mins and the polling period"
2525
},
2626
{
2727
"name": "totalTime",
@@ -33,7 +33,7 @@
3333
}
3434
},
3535
"display": 5,
36-
"description": "[min, max, avg] of time taken to get & process data,computed over the greater between the last 5 mins and the polling period"
36+
"description": "[min, max, avg] of time(ms) taken to get & process data,computed over the greater between the last 5 mins and the polling period"
3737
},
3838
{
3939
"name": "svcQsize",
@@ -45,7 +45,7 @@
4545
}
4646
},
4747
"display": 6,
48-
"description": "[min, max, avg] of service queue size, computed over the greater between the last 5 mins and the polling period"
48+
"description": "[min, max, avg] of service queue length, computed over the greater between the last 5 mins and the polling period"
4949
},
5050
{
5151
"name": "wrQsize",
@@ -57,7 +57,7 @@
5757
}
5858
},
5959
"display": 7,
60-
"description": "[min, max, avg] of write queue size, computed over the greater between the last 5 mins and the polling period"
60+
"description": "[min, max, avg] of write queue length, computed over the greater between the last 5 mins and the polling period"
6161
},
6262
{
6363
"name": "nodeQsize",
@@ -69,7 +69,7 @@
6969
}
7070
},
7171
"display": 8,
72-
"description": "[min, max, avg] of node queue size, computed over the greater between the last 5 mins and the polling period"
72+
"description": "[min, max, avg] of node queue length, computed over the greater between the last 5 mins and the polling period"
7373
},
7474
{
7575
"name": "rxBytes",
@@ -97,8 +97,14 @@
9797
{
9898
"name": "status",
9999
"type": "long",
100+
"description": "Service polling status code. 0 or 200 means successfully polled, -1 means time timeout, other values mean failed to poll"
101+
},
102+
{
103+
"name": "statusStr",
104+
"type": "string",
100105
"display": 3,
101-
"description": "Service polling status. 0 or 200 means successfully polled, -1 means time timeout, other values mean failed to poll"
106+
"description": "Service polling status string",
107+
"depends": "status"
102108
},
103109
{
104110
"name": "nodesPolledCnt",

suzieq/engines/pandas/sqPoller.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from suzieq.shared.poller_error_codes import SqPollerStatusCode
12
from suzieq.engines.pandas.engineobj import SqPandasEngine
23

34

@@ -16,8 +17,12 @@ def get(self, **kwargs):
1617
poll_period_exceeded = kwargs.pop('pollExcdPeriodCount', '')
1718
columns = kwargs.pop('columns', [])
1819
addnl_fields = kwargs.pop('addnl_fields', [])
20+
user_query = kwargs.pop('query_str', '')
1921

2022
fields = self.schema.get_display_fields(columns)
23+
user_query_cols = self._get_user_query_cols(user_query)
24+
addnl_fields += [x for x in user_query_cols if x not in addnl_fields]
25+
2126
if status and 'status' not in fields:
2227
addnl_fields.append('status')
2328

@@ -50,9 +55,13 @@ def get(self, **kwargs):
5055
else:
5156
add_filter += f'{add_prefix}pollExcdPeriodCount == 0'
5257

58+
if 'statusStr' in fields:
59+
df['statusStr'] = df.status.apply(self._get_status_str)
60+
5361
if not df.empty and add_filter:
5462
df = df.query(add_filter).reset_index(drop=True)
5563

64+
df = self._handle_user_query_str(df, user_query)
5665
return df.reset_index(drop=True)[fields]
5766

5867
def summarize(self, **kwargs):
@@ -72,3 +81,12 @@ def summarize(self, **kwargs):
7281
]
7382

7483
return super().summarize(**kwargs)
84+
85+
@staticmethod
86+
def _get_status_str(code: int) -> str:
87+
'''Function to catch exception'''
88+
try:
89+
# pylint: disable=no-value-for-parameter
90+
return SqPollerStatusCode(code).errstr
91+
except ValueError:
92+
return f'{code}'
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# List of normalized error codes used in the poller
2+
3+
from enum import IntEnum
4+
5+
# Ensure you never copy backwards compat values
6+
7+
8+
class SqPollerStatusCode(IntEnum):
9+
'''SuzieQ Poller Status Codes and their strings'''
10+
11+
OK = 0, 'OK'
12+
HTTP_OK = 200, 'OK'
13+
PERMISSION_DENIED = 1001, 'Permission Denied'
14+
UNAUTHORIZED = 1002, 'Unauthorized'
15+
LOGIN_FAIL = 1003, 'Login Failed'
16+
PRIV_ESC_FAIL = 1004, 'Privilege Escalation Failed'
17+
NON_FINAL_FAILURES = 1005, 'Dummy to mark boundary, never set'
18+
CMD_NOT_FOUND = 2006, 'Command Not Found'
19+
EMPTY_OUTPUT = 2007, 'Output Empty'
20+
INCOMPLETE_CMD = 2008, 'Command Incomplete'
21+
TIMEOUT = 2009, 'Command Timeout'
22+
DISABLED_FEATURE = 2010, 'Feature Disabled'
23+
CONNECT_FAIL = 2011, 'Connect Failed'
24+
PARSING_ERROR = 2012, 'Parsing Failed'
25+
UNSUPPORTED_SVC = 2013, 'Service Not Supported'
26+
UNSUPPORTED_CMD = 2014, 'Command Not Supported'
27+
NO_RT_TO_HOST = 2015, 'No Route to Host'
28+
VAR_NOT_SET = 2016, 'Variable Not Set'
29+
WAITING_FOR_VAR = 2017, 'Variable Waiting'
30+
ERR_OUTPUT = 2018, 'Command Failed'
31+
GEN_CLS_FAIL = 2019, 'Linux Cmd Failed'
32+
UNREACH_NET = 2020, 'Network Unreachable'
33+
NO_SVC_DEF = 2021, 'Service Not Defined'
34+
UNKNOWN_FAILURE = 2022, 'Unknown Failure'
35+
CONN_REFUSED = 2023, 'Connection Refused'
36+
UNEXPECTED_DISCONNECT = 2024, 'Unexpected Disconnect'
37+
38+
# Everything below this is for backward compat
39+
LINUX_OLD_CMD_NOT_FOUND = 1, 'Command Not Found'
40+
NXOS_CMD_NOT_FOUND = 16, 'Command Not Found'
41+
NXOS_YACNF = 20, 'Command Not Found'
42+
LINUX_CMD_NOT_FOUND = 127, 'Command Not Found'
43+
HTTP_EMPTY_OUTPUT = 204, 'Empty Output'
44+
OLD_EMPTY_OUTPUT = 244, 'Empty Output'
45+
HTTP_INCOMPLETE_CMD = 400, 'Incomplete Command'
46+
HTTP_LOGIN_FAIL = 401, 'Login Failed'
47+
HTTP_BAD_CMD = 404, 'Command Not Found'
48+
HTTP_YAIC = 405, 'Incomplete Command'
49+
HTTP_TIMEOUT = 408, 'Timeout'
50+
OLD_FEATURE_DISABLED = 418, 'Feature Disabled'
51+
OLD_PARSING_ERROR = 502, 'Parsing Error'
52+
OLD_PRIV_ESC_FAIL = -1, 'Privilege Escalation Failed'
53+
54+
def __new__(cls, code: int, errstr: str):
55+
obj = int.__new__(cls, code)
56+
obj._value_ = code
57+
obj.errstr = errstr
58+
59+
return obj
60+
61+
def is_error_code_final(self):
62+
'''is the node in stopped state'''
63+
return (self.value < self.NON_FINAL_FAILURES.value)

0 commit comments

Comments
 (0)