Ad Widget

Collapse

Monitor UniFi Controller via API without additional scripts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • michael.weber
    Senior Member
    • Nov 2015
    • 121

    #1

    Monitor UniFi Controller via API without additional scripts

    Hello,

    I created a template to monitor basic UniFI Controller stuff via Web API.
    Tested on zabbix 6.4 and unifi version 7.3.83.

    I am only using the WiFi stuff in unifi, but I will implement LAN/WWW/VPN in future. Let me know if you are interested in.

    If something is not working please create a github issue or fix it and create a PR
    It is based on this api: products:software:unifi-controller:api [Ubiquiti Community Wiki] (ubntwiki.com)

    Link: chises/zabbix-unifi: Zabbix Template to monitor UniFi Controller via web API (github.com)

    Click image for larger version

Name:	image.png
Views:	14919
Size:	51.3 KB
ID:	461861​​
    Attached Files
  • ashokdangol
    Junior Member
    • Mar 2023
    • 4

    #2
    Hello Michael, Thank you for this. I would love to see LAN/WWW/VPN in future. thanks for help zabbix community.

    Comment

    • michael.weber
      Senior Member
      • Nov 2015
      • 121

      #3
      I try to find some time next week and implement the basic monitoring for this

      Comment

      • guacia
        Junior Member
        • Jun 2022
        • 1

        #4
        Testing on my sites. Nice job. Definitely interested.

        Comment

        • BlacKTM
          Junior Member
          • Sep 2022
          • 2

          #5
          Hello
          Many thanks for your work.
          Also interested in the future.
          I have several switches, UBB,... and Unifi-API-Browser if you need a json

          Comment

          • michael.weber
            Senior Member
            • Nov 2015
            • 121

            #6
            Originally posted by BlacKTM
            Hello
            Many thanks for your work.
            Also interested in the future.
            I have several switches, UBB,... and Unifi-API-Browser if you need a json
            Hello,
            can you go to Data collection - Hosts - UniFi Host - Items - Discover Unifi Sites - Test and provide the Result? That would be great! Feel free to remove sensitive data.
            Click image for larger version

Name:	image.png
Views:	13761
Size:	106.4 KB
ID:	463767
            I added WWW, VPN, WAN and LAN Subsystem to the Template. Current version available in Github: chises/zabbix-unifi: Zabbix Template to monitor UniFi Controller via web API (github.com)

            If you provide your Output I can optimize the template.

            Comment

            • ashokdangol
              Junior Member
              • Mar 2023
              • 4

              #7
              Hello Guys, I tried using this template, all I get is this error and couldn't resolve it. Did I miss anything here?
              Click image for larger version

Name:	image.png
Views:	13637
Size:	17.3 KB
ID:	463838

              Comment

              • michael.weber
                Senior Member
                • Nov 2015
                • 121

                #8
                Originally posted by ashokdangol
                Hello Guys, I tried using this template, all I get is this error and couldn't resolve it. Did I miss anything here?
                Click image for larger version

Name:	image.png
Views:	13637
Size:	17.3 KB
ID:	463838
                This Template is using the Macro {HOST.CONN} fror the connection to the unifi controller.
                Your error message indicates that the server/proxy is not able to connect to the configued host name. Please provide the Host config in Zabbix (screenshot is fine) and try to reach the host via ICMP on the server/proxy (ping X.X.X.X).

                Comment

                • ashokdangol
                  Junior Member
                  • Mar 2023
                  • 4

                  #9
                  Click image for larger version

Name:	image.png
Views:	13584
Size:	42.0 KB
ID:	463854
                  I added interface as Agent and now I got this error. Sadly, I can't figureout why. My port is correct, I am able to login with username and password ​

                  Comment

                  • michael.weber
                    Senior Member
                    • Nov 2015
                    • 121

                    #10
                    error 404 means "not found". so this is not the correct hostname/IP and port combination.
                    Are you sure about port 443? Please try to connect with a webbrowser with your configured hostname/ip and port the the following url: https://<host/ip>:<port>/api/login
                    Click image for larger version

Name:	image.png
Views:	13589
Size:	7.3 KB
ID:	463856

                    Comment

                    • BlacKTM
                      Junior Member
                      • Sep 2022
                      • 2

                      #11
                      Hello
                      Originally posted by michael.weber
                      Hello,
                      can you go to Data collection - Hosts - UniFi Host - Items - Discover Unifi Sites - Test and provide the Result?
                      Sry for the delay...
                      Here is the result with your new yaml (My1stSite is intentionally empty and cannot be deleted due to Ubiquiti rules...) :​
                      Code:
                      [
                          {
                              "_id": "58eb9a9d328b8c7e935c13cf",
                              "name": "default",
                              "desc": "My1stSite",
                              "attr_hidden_id": "default",
                              "attr_no_delete": true,
                              "anonymous_id": "f5e92ef8-734c-4baa-8875-ef19be1f742c",
                              "health": [
                                  {
                                      "subsystem": "wlan",
                                      "status": "unknown",
                                      "num_ap": 0,
                                      "num_adopted": 0,
                                      "num_disabled": 0,
                                      "num_disconnected": 0,
                                      "num_pending": 0
                                  },
                                  {
                                      "subsystem": "wan",
                                      "num_gw": 0,
                                      "num_adopted": 0,
                                      "num_disconnected": 0,
                                      "num_pending": 0,
                                      "status": "unknown"
                                  },
                                  {
                                      "subsystem": "www",
                                      "status": "unknown"
                                  },
                                  {
                                      "subsystem": "lan",
                                      "status": "unknown",
                                      "num_sw": 0,
                                      "num_adopted": 0,
                                      "num_disconnected": 0,
                                      "num_pending": 0
                                  },
                                  {
                                      "subsystem": "vpn",
                                      "status": "unknown"
                                  }
                              ],
                              "num_new_alarms": 0
                          },
                          {
                              "_id": "601bcce9cb7a1c17a4e5511d",
                              "anonymous_id": "16121734-8641-4338-bb03-34c5318c2ff8",
                              "desc": "My2ndSite - Production",
                              "name": "5bnx7bri",
                              "health": [
                                  {
                                      "subsystem": "wlan",
                                      "num_user": 11,
                                      "num_guest": 2,
                                      "num_iot": 0,
                                      "tx_bytes-r": 208468,
                                      "rx_bytes-r": 25502,
                                      "status": "ok",
                                      "num_ap": 13,
                                      "num_adopted": 13,
                                      "num_disabled": 0,
                                      "num_disconnected": 0,
                                      "num_pending": 0
                                  },
                                  {
                                      "subsystem": "wan",
                                      "num_gw": 0,
                                      "num_adopted": 0,
                                      "num_disconnected": 0,
                                      "num_pending": 0,
                                      "status": "unknown"
                                  },
                                  {
                                      "subsystem": "www",
                                      "status": "unknown"
                                  },
                                  {
                                      "subsystem": "lan",
                                      "status": "ok",
                                      "num_user": 92,
                                      "num_guest": 0,
                                      "num_iot": 0,
                                      "tx_bytes-r": 857406,
                                      "rx_bytes-r": 240981,
                                      "num_sw": 6,
                                      "num_adopted": 6,
                                      "num_disconnected": 0,
                                      "num_pending": 0
                                  },
                                  {
                                      "subsystem": "vpn",
                                      "status": "unknown"
                                  }
                              ],
                              "num_new_alarms": 0
                          },
                          {
                              "_id": "608ffde6523db132c867b46d",
                              "anonymous_id": "481702b4-c686-4f2a-83aa-b64ae3fdfb65",
                              "desc": "My3rdSite - Production",
                              "name": "qrsj6nng",
                              "health": [
                                  {
                                      "subsystem": "wlan",
                                      "num_user": 5,
                                      "num_guest": 0,
                                      "num_iot": 0,
                                      "tx_bytes-r": 59144,
                                      "rx_bytes-r": 3624,
                                      "status": "ok",
                                      "num_ap": 1,
                                      "num_adopted": 1,
                                      "num_disabled": 0,
                                      "num_disconnected": 0,
                                      "num_pending": 0
                                  },
                                  {
                                      "subsystem": "wan",
                                      "num_gw": 0,
                                      "num_adopted": 0,
                                      "num_disconnected": 0,
                                      "num_pending": 0,
                                      "status": "unknown"
                                  },
                                  {
                                      "subsystem": "www",
                                      "status": "unknown"
                                  },
                                  {
                                      "subsystem": "lan",
                                      "status": "error",
                                      "num_user": 25,
                                      "num_guest": 0,
                                      "num_iot": 0,
                                      "tx_bytes-r": 755602,
                                      "rx_bytes-r": 456294,
                                      "num_sw": 3,
                                      "num_adopted": 4,
                                      "num_disconnected": 1,
                                      "num_pending": 0
                                  },
                                  {
                                      "subsystem": "vpn",
                                      "status": "unknown"
                                  }
                              ],
                              "num_new_alarms": 0
                          }
                      ]​
                      It just works perfectly
                      There are some minor tweaks on triggers but I'll write PR for that.
                      I'll also try to be inspired from your work to collect information from devices that only provide on the web ui and not by snmp.
                      Thanks again​
                      Last edited by BlacKTM; 03-05-2023, 16:44.

                      Comment

                      • michael.weber
                        Senior Member
                        • Nov 2015
                        • 121

                        #12
                        Thank you very much BlacKTM for your PR

                        Comment

                        • d0d0
                          Member
                          • May 2023
                          • 41

                          #13
                          Hi Michael,

                          thanks for your Unifi Controller template, it seems to work fine for. For my better understanding of the problems triggered I have some questions:
                          I am receiving these:
                          - UniFi LAN missing
                          - UniFi LAN Subsystem not "ok"
                          - UniFi VPN Subsystem is "unknown"
                          - UniFi WAN Subsystem is "unkown"
                          - UniFi WLAN Subsystem not "ok"
                          - UniFi WWW Subsystem is "unkown"

                          What is the actual meaning/background of each of these?

                          About my setup: I am using the Unifi app/controller to manage my APs and switches, but I do not have a Unifi gateway (comes in different Unifi products, which I do not intend to buy, as I am very happy with pfSense).

                          All of the above problems related to a missing gateway component, or are there some that should be OK and not a problem, even if I do not have a Unifi gateway?

                          Thanks for you time!

                          Comment

                          • ashokdangol
                            Junior Member
                            • Mar 2023
                            • 4

                            #14
                            Hello Micheal,
                            I tried a lot but unfortunately unable to get desired results.
                            Does this work with UDM pro router?

                            Comment

                            • michael.weber
                              Senior Member
                              • Nov 2015
                              • 121

                              #15
                              Hello, it should work.
                              Please go to Data collection - Host - Discover UniFi Sites Item and press Test
                              Click image for larger version

Name:	image.png
Views:	13563
Size:	155.7 KB
ID:	466535

                              Comment

                              Working...