Skip to content

Commit e539d97

Browse files
committed
Fixed issue in senders, removing remnants of dict()'s so they now properly process QResultsModel
1 parent eda65c5 commit e539d97

File tree

7 files changed

+23
-32
lines changed

7 files changed

+23
-32
lines changed

etc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 5a51d9b4967983aeff5225ed2caf732e6c11f540

lib/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def parse(self, poller : QPollConnector):
164164

165165
elif result_type == QConsts.RESULT_TABLE:
166166
for key, item in poller.results.items():
167-
parsed = self.format(item, poller.export_list())
167+
parsed = self.format(item)
168168
results.append(parsed)
169169
else:
170170
raise Exception('Error {} poller class has not correctly implemented get_result_type()'.format(poller.args.alias))

lib/formatters/csv.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import datetime
22

3-
from lib.base import QFormatConnector, QFormatterModel
3+
from lib.base import QFormatConnector, QFormatterModel, QResultsModel
44

55
########################################################################################################################
66
## Config Models
@@ -29,7 +29,7 @@ def prerequisites(self, initiator):
2929
pass
3030

3131

32-
def format(self, row, export_keys : list) -> str:
32+
def format(self, row : QResultsModel) -> str:
3333
"""
3434
Takes a dictionary, converting into key-paired comma seperated row
3535
"""
@@ -38,9 +38,8 @@ def format(self, row, export_keys : list) -> str:
3838
if self.args.prefix_timestamp and self.args.prefix_timestamp!=False and self.args.prefix_timestamp!="False":
3939
output = datetime.now().strftime(self.args.prefix_timestamp) + ","
4040

41-
for key in export_keys:
42-
if key in row:
43-
print(key)
44-
output = output + f"{key}='{row[key]}',"
41+
c = dict(row)
42+
for key, value in c.items():
43+
output = output + f"{key}='{value}',"
4544

4645
return output

lib/formatters/dict.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import datetime
22

33
import json
4-
from lib.base import QFormatConnector, QFormatterModel
4+
from lib.base import QFormatConnector, QFormatterModel, QResultsModel
55
from pprint import pprint
66

77
########################################################################################################################
@@ -39,17 +39,12 @@ def prerequisites(self, initiator):
3939
pass
4040

4141

42-
def format(self, row, export_keys : list) -> dict:
42+
def format(self, row : QResultsModel) -> dict:
4343
"""
44-
Takes a dictionary, converting into key-paired comma seperated row
44+
Takes a QResultsModel, returns it as a Dict, which is later sent to a compatible sender (e.g. OpenSearch)
4545
"""
46-
output = dict()
47-
output = row
48-
#if self.args["prefix_timestamp"]:
49-
# for key in export_keys:
50-
# if key in row:
51-
# output[key] = row[key]
52-
if self.args.prefix_timestamp and self.args.prefix_timestamp!=False and self.args.prefix_timestamp!="False":
53-
output["time"] = datetime.now().strftime(self.args.prefix_timestamp)
54-
55-
return output
46+
47+
if self.args.prefix_timestamp and self.args.prefix_timestamp!=False:
48+
row.time = datetime.now().strftime(self.args.prefix_timestamp)
49+
50+
return dict(row)

lib/formatters/json.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from datetime import datetime
2-
32
import json
4-
from lib.base import QFormatConnector, QFormatterModel
5-
3+
from lib.base import QFormatConnector, QFormatterModel, QResultsModel
4+
from pprint import pprint
65

76
########################################################################################################################
87
## Config Models
@@ -38,14 +37,12 @@ def prerequisites(self, initiator):
3837
pass
3938

4039

41-
def format(self, row, export_keys : list) -> str:
40+
def format(self, row : QResultsModel) -> str:
4241
"""
43-
Takes a dictionary, converting into key-paired comma seperated row
42+
Takes a QResultsModel, returns it as a JSON string, which is later sent to a compatible sender (e.g. SplunkHEC)
4443
"""
45-
output = ""
44+
4645
if self.args.prefix_timestamp and self.args.prefix_timestamp!=False:
4746
row.time = datetime.now().strftime(self.args.prefix_timestamp)
4847

49-
output = json.dumps(dict(row))
50-
51-
return output
48+
return json.dumps(dict(row))

lib/pollers/snmp.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ class QSNMPNetResultModel(QResultsModel):
101101

102102
sysName: str
103103
sysIP: str
104-
deviceType: str = ""
105104
ifSpeedOut: int = None
106105
ifSpeedIn: int = None
107106
ifSpeedTotal: int
@@ -213,7 +212,7 @@ def query(self):
213212
applog.debug("Skipping {} interface {}, its not in the configuration for this connector".format(args.host, row['ifDescr']))
214213
else:
215214
applog.debug("First run - Values such as ifAlias and host etc are not set on this initial run!")
216-
results = cn
215+
results = dict()
217216

218217
self.previous_time = ct
219218
self.previous_net = cn

qasa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def global_setup(show_output = True):
2121
## Determine path for config files
2222
workdir = dir_path = os.path.dirname(os.path.realpath(__file__))
2323
workdir += "/etc" if ENV_TYPE == "production" else "/etc-sample"
24-
print("Workdir: {}".format(workdir))
24+
applog.info("Workdir: {}".format(workdir))
2525

2626
## Load config files
2727
settings_path = workdir + "/settings.yml"

0 commit comments

Comments
 (0)