Skip to content

Commit

Permalink
Escape fix. No need for hostname - as not using regex for query
Browse files Browse the repository at this point in the history
  • Loading branch information
juztas committed Jul 24, 2024
1 parent 025ff9e commit 987e999
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion autogole-api/src/python/RTMonLibs/GeneralLibs.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def getWebContentFromURL(url, logger, raiseEx=True):

def escape(invalue):
"""Escape special characters for regex matching"""
return invalue.replace("+", "\\+")
return invalue.replace("+", "[+]")

class ExceptionTemplate(Exception):
"""Exception template."""
Expand Down
6 changes: 3 additions & 3 deletions autogole-api/src/python/RTMonLibs/Template.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def findIntf(interfaces):
panels = dumpJson(self._t_loadTemplate("switchflow.json"), self.logger)
panels = panels.replace("REPLACEME_DATASOURCE", str(self.t_dsourceuid))
panels = panels.replace("REPLACEME_SITENAME", sitename)
panels = panels.replace("REPLACEME_HOSTNAME", escape(hostname))
panels = panels.replace("REPLACEME_HOSTNAME", hostname)
panels = panels.replace("REPLACEME_INTERFACE", escape(intfline))
panels = loadJson(panels, self.logger)
out += self.addRowPanel(row, panels, True)
Expand Down Expand Up @@ -537,7 +537,7 @@ def _t_addSwitchL2Debugging(self, sitehost, interfaces, refid):
query = copy.deepcopy(origin_query)
# Add state and check if it receives information from snmp monitoring
query['datasource']['uid'] = str(self.t_dsourceuid)
query['expr'] = f'count(interface_statistics{{sitename="{sitename}", hostname="{escape(hostname)}"}}) OR on() vector(0)'
query['expr'] = f'count(interface_statistics{{sitename="{sitename}", hostname="{hostname}"}}) OR on() vector(0)'
query['legendFormat'] = f'SNMP Data available for {sitename} {hostname}'
query['refId'] = f'A{refid}'
refid += 1
Expand All @@ -551,7 +551,7 @@ def _t_addSwitchL2Debugging(self, sitehost, interfaces, refid):
for mhost, macaddr in self.mac_addresses.items():
query = copy.deepcopy(origin_query)
query['datasource']['uid'] = str(self.t_dsourceuid)
query['expr'] = f'sum(mac_table_info{{sitename="{sitename}",hostname="{escape(hostname)}", macaddress="{macaddr}", vlan="{vlan}"}}) OR on() vector(0)'
query['expr'] = f'sum(mac_table_info{{sitename="{sitename}",hostname="{hostname}", macaddress="{macaddr}", vlan="{vlan}"}}) OR on() vector(0)'
query['legendFormat'] = f'MAC address of {mhost} visible in mac table ({vlan})'
query['refId'] = f'A{refid}'
refid += 1
Expand Down

0 comments on commit 987e999

Please sign in to comment.