Vadims06 / ospfwatcher

History of all changes in OSPF Topology
https://topolograph.com/ospf-monitoring
GNU General Public License v3.0
57 stars 8 forks source link

watcher api ValueError: UNAUTHORIZED #3

Closed prokocool1987 closed 1 year ago

prokocool1987 commented 1 year ago

Hello, i've get an issue with a watcher container. it restarts cyclically with the error: UNAUTHORIZED, Graph Parsing was unsuccessful graph_obj = GraphFromTopolograph() File "/home/watcher/watcher/Helper.py", line 705, in init self.init_graph() File "/home/watcher/watcher/Helper.py", line 735, in init_graph raise ValueError(f"{r_post.reason}, {_error}") ValueError: UNAUTHORIZED, Graph Parsing was unsuccessful

Login and pass are correct and i've added source networks via web form. I'm using a topolograph docker version.

Vadims06 commented 1 year ago

Hi @prokocool1987 , UNAUTHORIZED error gives me a clue that it might be because of missed these variables: TOPOLOGRAPH_USER_LOGIN TOPOLOGRAPH_USER_PASS Make sure that such variables are set properly and give me an update.

prokocool1987 commented 1 year ago

Hello, Vadim. Thank you for your reply. These variables are set. And i can make a GET request via web api swagger with this credentials, but my POST request in watcher section return 401 error.

Vadims06 commented 1 year ago

@prokocool1987, I guess that something is wrong with Quagga's output. Try to test it like this: Go to ospfwatcher's repository directory and launch a new container docker run --env-file ./.env -it ospfwatcher_watcher:latest /bin/bash Inside container run:

python3
import os
import requests
from Helper import QConnecter
quagga_conn = QConnecter()
lsdb_output = quagga_conn.get_lsdb_output()

Make sure that you get OSPF LSDB from quagga instance print(lsdb_output) If you see the full LSDB output - proceed with further steps: Try to GET all graphs

_login, _pass = os.getenv('TOPOLOGRAPH_WEB_API_USERNAME_EMAIL'), os.getenv('TOPOLOGRAPH_WEB_API_PASSWORD')
_host, _port = os.getenv('TOPOLOGRAPH_HOST'), os.getenv('TOPOLOGRAPH_PORT')
r_get = requests.get(f'http://{_host}:{_port}/api/graph', auth=(_login, _pass))
r_get.ok
r_get.json()

Try to POST your OSPF LSDB

r_post = requests.post(f'http://{_host}:{_port}/api/watcher', auth=(_login, _pass), 
                            json={'lsdb_output': lsdb_output, 'vendor_device': 'Quagga'}, timeout=(5, 30))
r_get.ok
r_get.json()

The error states that something is wrong with lsdb_output, so I guess we need to check it first.

prokocool1987 commented 1 year ago

@Vadims06 , i've done tests: docker run --env-file ./.env --network="host" -it ospfwatcher_watcher:latest /bin/bash /home/watcher/watcher# python3 Python 3.9.16 (main, Feb 9 2023, 05:42:57) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information.

import os import requests from Helper import QConnecter quagga_conn = QConnecter()>>> from Helper import QConnecter quagga_conn = QConnecter() lsdb_output = quagga_conn.get_lsdb_output() print(lsdb_output) OSPF Router with ID (172.20.0.1)

            Router Link States (Area 0.0.0.1)

LS age: 78 Options: 0x2 : *|-|-|-|-|-|E|- LS Flags: 0x3
Flags: 0x0 LS Type: router-LSA Link State ID: 172.20.0.1 Advertising Router: 172.20.0.1 LS Seq Number: 80000004 Checksum: 0x01db Length: 24

Number of Links: 0

OSPF Router with ID (172.20.0.1)

            Net Link States (Area 0.0.0.1)

_login, _pass = os.getenv('TOPOLOGRAPH_WEB_API_USERNAME_EMAIL'), os.getenv('TOPOLOGRAPH_WEB_API_PASSWORD') _host, _port = os.getenv('TOPOLOGRAPH_HOST'), os.getenv('TOPOLOGRAPH_PORT') r_get = requests.get(f'http://{_host}:{_port}/api/graph', auth=(_login, _pass)) r_get.ok True r_get.json() [{'graph_time': '27Feb2023_03h55m29s_13_hosts_demo', 'hosts': {'count': 13}, 'networks': {'backuped': 18, 'count': 40, 'notbackuped': 22, 'url_link': 'http://10.1.16.57:8080/api/network/27Feb2023_03h55m29s_13_hosts_demo'}, 'timestamp': '2023-02-27T03:55:29.627000'}] r_post = requests.post(f'http://{_host}:{_port}/api/watcher', auth=(_login, _pass), ... json={'lsdb_output': lsdb_output, 'vendor_device': 'Quagga'}, timeout=(5, 30)) r_get.ok True r_get.json() [{'graph_time': '27Feb2023_03h55m29s_13_hosts_demo', 'hosts': {'count': 13}, 'networks': {'backuped': 18, 'count': 40, 'notbackuped': 22, 'url_link': 'http://10.1.16.57:8080/api/network/27Feb2023_03h55m29s_13_hosts_demo'}, 'timestamp': '2023-02-27T03:55:29.627000'}] r_post.ok
False r_post.json() 'Graph Parsing was unsuccessful'

Vadims06 commented 1 year ago

@prokocool1987 I guess that you already set TEST_MODE to "False", right? I also noticed that LSDB has Number of Links: 0. Does Quagga have any OSPF neighbors? GRE's network should be included into Quagga's config file quagga/config/ospfd.conf If not, that causes Graph Parsing was unsuccessful error, because LSDB is empty.

prokocool1987 commented 1 year ago

@Vadims06 , you're right. I don't setup a gre runnel. After i did it, the watcher container works fine. Thank you for your support. The issue can be closed.

Vadims06 commented 1 year ago

@prokocool1987, I improved an error message to get a better understanding of the issue. If GRE tunnel is not ready and no OSPF neighbors, ospfwatcher will print:

Traceback (most recent call last):
  File "/home/watcher/watcher/pytail.py", line 63, in <module>
    graph_obj = GraphFromTopolograph()
  File "/home/watcher/watcher/Helper.py", line 717, in __init__
    self.init_graph()
  File "/home/watcher/watcher/Helper.py", line 727, in init_graph
    raise ValueError('Quagga does not have any neighbors, please setup GRE tunnel and build OSPF adjacency first.')
ValueError: Quagga does not have any neighbors, please setup GRE tunnel and build OSPF adjacency first.

Could you please share your experience of OSPFWatcher installation, was it difficult to setup, is it enough to configure Quagga via env variables? I will be happy to take this into account for getting this service better. Please fill free to email me to admin at topolograph.com