Skip to content

Commit c0be42c

Browse files
committed
Devices: Fix how device interacts with sqpoller table
Essentially, we want the device table to show all devices in the inventory, even those that were never polled due to whatever reason that connectivity could not be established. To do this, we pull the info about devices from the poller table. However, we were pulling all devices from the poller table which meant even those that were successful and were already in the device table. This meant any filter the user had applied such as specifying model, vendor, OS, etc. were lost when we did the merge. To avoid this issue, but stay true to the reason we were pulling data from the poller table, we change the poller query to only return info about devices that have failed. This fix however has the limitation that it doesn't handle the case where a device has failed presently, but it once was polled, and a user filter prevents a device from being selected, by the device table. We'll tackle that case separately. Signed-off-by: Dinesh Dutt <[email protected]>
1 parent c782691 commit c0be42c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

suzieq/engines/pandas/device.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,15 @@ def get(self, **kwargs):
5252
if view == 'latest' and 'status' in df.columns:
5353
df['status'] = np.where(df.active, df['status'], 'dead')
5454

55-
poller_df = pd.DataFrame()
55+
poller_df: pd.DataFrame = pd.DataFrame()
56+
57+
# Retrieve the devices that have possibly not made it into the device
58+
# list because they never could connect due to any reason
5659
if not ignore_neverpoll:
5760
poller_df = self._get_table_sqobj('sqPoller').get(
5861
namespace=kwargs.get('namespace', []),
5962
hostname=kwargs.get('hostname', []),
60-
service='device',
63+
service='device', status='fail',
6164
columns='namespace hostname status timestamp'.split())
6265

6366
if not poller_df.empty:
@@ -77,7 +80,7 @@ def get(self, **kwargs):
7780
.reset_index(drop=True)
7881

7982
df = df.merge(poller_df, on=['namespace', 'hostname'],
80-
how='outer', suffixes=['', '_y']) \
83+
how='outer', suffixes=('', '_y')) \
8184
.fillna({'bootupTimestamp': 0,
8285
'active': True})
8386

@@ -121,6 +124,7 @@ def get(self, **kwargs):
121124
# The poller merge kills the filtering we did earlier, so redo:
122125
if status:
123126
df = df.loc[df.status.isin(status)]
127+
124128
if os_version:
125129
opdict = {'>': operator.gt, '<': operator.lt, '>=': operator.ge,
126130
'<=': operator.le, '=': operator.eq, '!': operator.ne}

0 commit comments

Comments
 (0)