binarybear-de / cmk_check_unifi-controller

Local Check for Check_MK to get information about UniFi devices from Controller
21 stars 2 forks source link

UDM Pro #9

Open gnoffer opened 2 years ago

gnoffer commented 2 years ago

With UDMM-Pro i got following error:

root@vpn00:~# ./check_unifi-controller.sh.1 parse error: Invalid numeric literal at line 2, column 0 ./check_unifi-controller.sh.1: Zeile 59: [: =: Einstelliger (unärer) Operator erwartet. parse error: Invalid numeric literal at line 2, column 0 parse error: Invalid numeric literal at line 2, column 0 0 UniFi-Controller - Hostname: , Build , Check-Script BUILD 2021-02-27 parse error: Invalid numeric literal at line 2, column 0 0 UniFi-Devices devices=|sites=|unamed=0|unadopted=0 devices on sites - no unnamed or unadopted devices found

as told on https://ubntwiki.com/products/software/unifi-controller/api for UDM pro there is an other api login link, i change it in the script. i also have changed BASEURL to

BASEURL="https://192.168.22.1/proxy/network"

but both without success.

root@vpn00:/usr/lib/check_mk_agent/local# ./check_unifi-controller.sh parse error: Invalid numeric literal at line 2, column 0 ./check_unifi-controller.sh: Zeile 59: [: =: Einstelliger (unärer) Operator erwartet. parse error: Invalid numeric literal at line 2, column 0 parse error: Invalid numeric literal at line 2, column 0 0 UniFi-Controller - Hostname: , Build , Check-Script BUILD 2021-02-27 parse error: Invalid numeric literal at line 2, column 0 0 UniFi-Devices devices=|sites=|unamed=0|unadopted=0 devices on sites - no unnamed or unadopted devices found

binarybear-de commented 2 years ago

Try updating to latest version first - I fixed some variable handling and added some curl headers referenced here: https://github.com/binarybear-de/cmk_check_unifi-controller/issues/8

I cannot really provide any information for UDM since I dont have one.. I just experimented with those queries in my browser until I got the values that I needed...

If you found a working query, feel free to provide it here :)

gnoffer commented 2 years ago

Following Results:

1) plain test with last build without edits from myself: root@vpn00:/usr/lib/check_mk_agent/local# ./check_unifi-controller.sh parse error: Invalid numeric literal at line 1, column 4 parse error: Invalid numeric literal at line 1, column 4 parse error: Invalid numeric literal at line 1, column 4 0 UniFi-Controller - Hostname: , Build , Check-Script BUILD 2021-11-04-v3 parse error: Invalid numeric literal at line 1, column 4 0 UniFi-Devices devices=|sites=|unamed=0|unadopted=0 devices on sites - no unnamed or unadopted devices found

2) edit baseurl to BASEURL="https://192.168.22.1/proxy/network" root@vpn00:/usr/lib/check_mk_agent/local# ./check_unifi-controller.sh parse error: Invalid numeric literal at line 2, column 0 parse error: Invalid numeric literal at line 2, column 0 parse error: Invalid numeric literal at line 2, column 0 0 UniFi-Controller - Hostname: , Build , Check-Script BUILD 2021-11-04-v3 parse error: Invalid numeric literal at line 2, column 0 0 UniFi-Devices devices=|sites=|unamed=0|unadopted=0 devices on sites - no unnamed or unadopted devices found

3) edit loginController BaseURL ...snip... $BASEURL/api/auth/login > /dev/null) ; ...snip... Result: root@vpn00:/usr/lib/check_mk_agent/local# ./check_unifi-controller.sh parse error: Invalid numeric literal at line 2, column 0 parse error: Invalid numeric literal at line 2, column 0 parse error: Invalid numeric literal at line 2, column 0 0 UniFi-Controller - Hostname: , Build , Check-Script BUILD 2021-11-04-v3 parse error: Invalid numeric literal at line 2, column 0 0 UniFi-Devices devices=|sites=|unamed=0|unadopted=0 devices on sites - no unnamed or unadopted devices found

what else can we test? is there a way for better debug?

gnoffer commented 2 years ago

So with this settings i get a working login and a cookie, BASEURL=https://192.168.22.1 in executabel file i changed every BASEURL/xxx path to BASEURL/proxy/network/xxx but not for Login.

but still with following errors: root@vpn00:/usr/lib/check_mk_agent/local# ./check_unifi-controller.sh parse error: Invalid numeric literal at line 2, column 0 parse error: Invalid numeric literal at line 2, column 0 parse error: Invalid numeric literal at line 2, column 0 0 UniFi-Controller - Hostname: , Build , Check-Script BUILD 2021-11-04-v3 parse error: Invalid numeric literal at line 2, column 0 0 UniFi-Devices devices=|sites=|unamed=0|unadopted=0 devices on sites - no unnamed or unadopted devices found

cookie: root@vpn00:/usr/lib/check_mk_agent/local# cat /tmp/unifi-check-cookie # Netscape HTTP Cookie File # https://curl.se/docs/http-cookies.html # This file was generated by libcurl! Edit at your own risk. #HttpOnly_192.168.22.1 FALSE / TRUE 0 TOKEN XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

gnoffer commented 2 years ago

OK, after some Testing, following Commands are working:

rm /tmp/unifi-check-cookie

curl --insecure --cookie /tmp/unifi-check-cookie --cookie-jar /tmp/unifi-check-cookie --header "Content-Type: application/json" --request POST --data '{"username":"cmk","password":"*****"}' https://192.168.22.1/api/auth/login

curl --insecure --cookie /tmp/unifi-check-cookie --cookie-jar /tmp/unifi-check-cookie --header "Content-Type: application/json" --request GET --data "{}" https://192.168.22.1/proxy/network/api/s/default/self

curl --insecure --cookie /tmp/unifi-check-cookie --cookie-jar /tmp/unifi-check-cookie --header "Content-Type: application/json" --request GET --data "{}" https://192.168.22.1/proxy/network/api/self/sites

curl --insecure --cookie /tmp/unifi-check-cookie --cookie-jar /tmp/unifi-check-cookie --header "Content-Type: application/json" --request GET --data "{}" https://192.168.22.1/proxy/network/api/s/default/stat/device

gnoffer commented 2 years ago

i've got it to work.

you can download the working script from now on for 30 days from https://easyupload.io/h88scn

i've made a pullrequest for it as a new file

other Options: CURLOPTS="--insecure --tlsv1.2 --header \"Content-Type: application/json\"" -> you have to escape the " BASEURL=https://192.168.22.1

techsolo12 commented 2 years ago

For me your script wouldn't work proberly. I had edited the unifi.cfg to the value from your last post and put your script to /usr/lib/check_mk_agent/local/ the script is owned by root and is executable. The unifi.cfg is also owned by root and has permissions 700.

I got following error: root@CheckMK:/usr/lib/check_mk_agent/local# sh check_unifi-controller_udm.sh : not found-controller_udm.sh: 5: : not found-controller_udm.sh: 9: stat: der Aufruf von statx für '/etc/check_mk/unifi.cfg'$'\r' ist fehlgeschlagen: Datei oder Verzeichnis nicht gefunden stat: der Aufruf von statx für '/etc/check_mk/unifi.cfg'$'\r' ist fehlgeschlagen: Datei oder Verzeichnis nicht gefunden : not found-controller_udm.sh: 13: check_unifi-controller_udm.sh: 86: Syntax error: word unexpected (expecting "do")

When i run it with ./check_unifi-controller_udm.sh i got this error: root@CheckMK:/usr/lib/check_mk_agent/local# ./check_unifi-controller_udm.sh -bash: ./check_unifi-controller_udm.sh: /bin/bash^M: Defekter Interpreter: Datei oder Verzeichnis nicht gefunden

Which means that the interpreter will not found. But with the old script i ddin't got this error.

techsolo12 commented 2 years ago

I tried to got the cookies with manuell comamnd like, but only the error "Not Found". When i type the first command in browser i got the error "Method Not Allowed"

curl --insecure --cookie /tmp/unifi-check-cookie --cookie-jar /tmp/unifi-check-cookie --header "Content-Type: application/json" --request POST --data '{"username":"MYUSERNAME","password":"SUPERDUPERSECRET"}' https://10.10.10.1/api/auth/login

curl --insecure --cookie /tmp/unifi-check-cookie --cookie-jar /tmp/unifi-check-cookie --header "Content-Type: application/json" --request GET --data "{}" https://10.10.10.1/proxy/network/api/s/default/self

curl --insecure --cookie /tmp/unifi-check-cookie --cookie-jar /tmp/unifi-check-cookie --header "Content-Type: application/json" --request GET --data "{}" https://10.10.10.1/proxy/network/api/self/sites

curl --insecure --cookie /tmp/unifi-check-cookie --cookie-jar /tmp/unifi-check-cookie --header "Content-Type: application/json" --request GET --data "{}" https://10.10.10.1/proxy/network/api/s/default/stat/device