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

    #31
    Are you looking for someone specific based on a mac adress? Currently that is not working, but based on community documenation this could be possible: the api provides information about connected clients.
    if you let me know based for what information you are looking for the client (mac/hostname) I can try to add this.

    Comment

    • tikoretech
      Junior Member
      • Dec 2023
      • 10

      #32
      Originally posted by michael.weber
      Are you looking for someone specific based on a mac adress? Currently that is not working, but based on community documenation this could be possible: the api provides information about connected clients.
      if you let me know based for what information you are looking for the client (mac/hostname) I can try to add this.
      I understand, the logic of what I was looking for is the following:
      I have a guest network, with a basic password, but I have several improper connections to it (The network was like this at the request of the Board), if I received any notification when someone connected to it, regardless of MAC or Hostname, I could immediately evaluate and perform blocking if necessary, do you understand the logic I am looking for?​

      Comment

      • michael.weber
        Senior Member
        • Nov 2015
        • 121

        #33
        Yes i got it.
        So the most easiest is to create a trigger if the number of connected users increase. But this is not a good solution: image a user leaves the wifi and a new connects, the count stays the same, but a new user.
        I will invest some time in the API and collect all clients based on their mac. If a new mac shows up a trigger will be created, this is what you are looking for.

        Let me check the current code for some clean up and I think at sunday i can provide a modified template.

        Comment

        • tikoretech
          Junior Member
          • Dec 2023
          • 10

          #34
          Originally posted by michael.weber
          Yes i got it.
          So the most easiest is to create a trigger if the number of connected users increase. But this is not a good solution: image a user leaves the wifi and a new connects, the count stays the same, but a new user.
          I will invest some time in the API and collect all clients based on their mac. If a new mac shows up a trigger will be created, this is what you are looking for.

          Let me check the current code for some clean up and I think at sunday i can provide a modified template.
          Show!!! I don't even know how I can thank you... And again, thank you very much for the correction! I'm already applying the update here to the 4 controllers I manage!!!

          Comment

          • tikoretech
            Junior Member
            • Dec 2023
            • 10

            #35
            Originally posted by tikoretech

            Show!!! I don't even know how I can thank you... And again, thank you very much for the correction! I'm already applying the update here to the 4 controllers I manage!!!
            Hello michael.weber ! All good? I believe you haven't had time yet to check the connections on the network, please let me know if you have any news...
            Thanks again for your help.​

            Comment

            • tikoretech
              Junior Member
              • Dec 2023
              • 10

              #36
              Originally posted by tikoretech

              Hello michael.weber ! All good? I believe you haven't had time yet to check the connections on the network, please let me know if you have any news...
              Thanks again for your help.​
              Hello! Did you manage to evolve at this point?

              Comment

              • blacklife
                Junior Member
                • May 2023
                • 1

                #37
                michael.weber
                Need your help or advice on how to complete the setup.

                The login is correct, i can log in to the controller

                UniFi OS 3.2.10
                UniFi Network Application 8.0.28

                do I need to downgrade to work properly?

                Thanks.

                Click image for larger version

Name:	image.png
Views:	1802
Size:	32.4 KB
ID:	477890

                Comment

                • tlpeter
                  Junior Member
                  • Mar 2024
                  • 1

                  #38
                  I am having the same problem as blacklife .
                  I get a 401 as well while i am a 100% my credentials are correct
                  error reason for "Unifi:unifi.sites" changed: Cannot execute script: Login failed with status code 401: {"error":{"code":401,"message":"Unauthorized"}}
                  Could this be because of a recent change for user to username in the API?

                  Comment

                  • dougcast
                    Junior Member
                    • Jun 2024
                    • 1

                    #39
                    From your template I created a custom one and made one that would suit me, I needed to know the name, state and uptime at least for my environment.
                    Click image for larger version

Name:	image.png
Views:	1372
Size:	72.2 KB
ID:	485192
                    Click image for larger version

Name:	image.png
Views:	1338
Size:	16.2 KB
ID:	485193

                    ***** https://github.com/dougcast/TEMPLATE...LLER/tree/main

                    As I created it from yours, I decided to distribute it to the public as well.

                    Comment

                    • tomtson
                      Junior Member
                      • Jul 2024
                      • 1

                      #40
                      Same issue as blacklife
                      UnifiOS: 3.2.12
                      Network: 8.1.127

                      When running Data Collection > Hosts > Host/Items > Discovery Unifi Sites > Test, with the parameters:
                      MyPassword
                      443
                      MyUser
                      MyHostIP

                      I get a 401 Unauthorized error.

                      When running the following curl command, I get a HTTP200.

                      curl -k -X POST --data '{"username": "MyUser", "password": "MyPassword"}' --header 'Content-Type: application/json' -c cookie.txt https://MyHostIP:443/api/auth/login

                      I've modified the script to use the endpoint "/api/auth/login" as this is when trying to access a UDM Pro. I've also tested changing the Content-Type header from its original x-www-form-urlencoded to application/json. Neither have changed the result in Zabbix.
                      Any further ideas?

                      Comment

                      • sokeada
                        Junior Member
                        • Jun 2024
                        • 25

                        #41
                        Originally posted by michael.weber
                        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:	7690 Size:	51.3 KB ID:	461861​​

                        Dear Michael,

                        I really appreciate your template, this is really awesome. By the way, do you have any plan to release the template for UAP and USW as well?


                        Appreciate your work,

                        Sokeada

                        Comment

                        • Fernandoqcn
                          Junior Member
                          • Nov 2024
                          • 1

                          #42
                          Click image for larger version

Name:	image.png
Views:	1044
Size:	8.4 KB
ID:	494268
                          Good evening, I'm also having the same 401 error when accessing the new API, has anyone managed to access it?

                          Comment

                          • marcoue
                            Junior Member
                            • Jan 2025
                            • 1

                            #43
                            Good day! Thanks for your nice template. It was easy to get it running on my UDM-SE but no luck with my USW switch. Anything special to do to activate the monitoring on the switch itself? Thanks again!

                            Comment

                            • timau
                              Junior Member
                              • Jan 2025
                              • 1

                              #44
                              Hi and thanks for the template - Im very new to Zabbix.

                              I have installed your template and connected to a Unifcontroller - all worked great and its discovered all my sites and devices however like previous post I'm receiving a ton of infomation/problems that dont seem to be relevent to all my sites. 99% dont have a Unifi gateway as per below:

                              Is there a way to remove all this extra noise? I also see that it must poll the Controller and occasionally it doesn't see a device so errors then finds it next poll and recovers (the device has been there all the time)

                              Thanks!

                              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?

                              Comment

                              • kristianf
                                Junior Member
                                • Jan 2025
                                • 2

                                #45
                                hello, i am trying to connect to unifi controller with the template. but i am not able to get i true.

                                unifi network version: 9.0.108
                                Zabbix: 7.2.0

                                the unifi network runs i multi site.

                                and the error i am getting is: Cannot execute script: No JSON Response

                                Comment

                                Working...