Skip to content

Commit 81e7e6a

Browse files
Panos node: clean up and better log messages
Signed-off-by: Claudio Usai <[email protected]> Co-authored-by: Luca Nicosia <[email protected]>
1 parent 808aa24 commit 81e7e6a

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

suzieq/poller/worker/nodes/node.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,7 @@ class PanosNode(Node):
18971897
'''Node object representing access to a Palo Alto Networks FW'''
18981898

18991899
async def _fetch_init_dev_data(self):
1900+
discovery_cmd = 'show system info'
19001901
try:
19011902
res = []
19021903
# temporary hack to detect device info using ssh
@@ -1905,7 +1906,7 @@ async def _fetch_init_dev_data(self):
19051906
self.address, port=22, username=self.username,
19061907
password=self.password, known_hosts=None) as conn:
19071908
async with conn.create_process() as process:
1908-
process.stdin.write("show system info\n")
1909+
process.stdin.write(f'{discovery_cmd}\n')
19091910
output = ""
19101911
output += await process.stdout.read(1)
19111912
try:
@@ -1929,20 +1930,21 @@ async def _fetch_init_dev_data(self):
19291930
await self.get_api_key()
19301931
except asyncssh.misc.PermissionDenied:
19311932
self.logger.error(
1932-
f'Permission denied for {self.address}:{self.port}')
1933+
f'{self.address}:{self.port}: permission denied')
19331934
self._retry -= 1
1934-
except Exception:
1935-
self.logger.warning(
1936-
f'Cannot parse device data from {self.address}:{self.port}')
1935+
except Exception as e:
1936+
self.logger.error(
1937+
f'{self.hostname}:{self.port}: Command "{discovery_cmd}" '
1938+
f'failed due to {e}')
19371939

19381940
async def get_api_key(self):
19391941
"""Authenticate to get the api key needed in all cmd requests"""
19401942
url = f"https://{self.address}:{self.port}/api/?type=keygen&user=" \
19411943
f"{self.username}&password={self.password}"
19421944

1945+
if not self._retry:
1946+
return
19431947
async with self.cmd_pacer(self.per_cmd_auth):
1944-
if not self._retry:
1945-
return
19461948
async with self._session.get(url, timeout=self.connect_timeout) \
19471949
as response:
19481950
status, xml = response.status, await response.text()
@@ -2058,7 +2060,6 @@ async def _rest_gather(self, service_callback, cmd_list, cb_token,
20582060
if status == 200:
20592061
json_out = json.dumps(
20602062
xmltodict.parse(xml))
2061-
self.logger.info(f"{cmd} {status}")
20622063
result.append({
20632064
"status": status,
20642065
"timestamp": now,

0 commit comments

Comments
 (0)