Ad Widget

Collapse

Monitor UniFi Controller via API without additional scripts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dancastroofc
    Junior Member
    • Apr 2022
    • 1

    #16
    Would it be possible to convert this template to be used in Zabbix 6.0 LTS?

    Comment

    • Yamdar
      Junior Member
      • Nov 2023
      • 1

      #17
      Thanks for this template.
      I was able to import it on Zabbix 6.0 and it's working fine for Unifi Controller on linux servers.

      I am trying to make it work against UDM or CloudKey Gen2

      I know for a fact that,
      1: Port is different, it uses 443 as default
      2: Login URL API is different, it uses: /api/auth/login instead of /api/login
      3: API for Network app (on cloud key) is reachable through: /proxy/network/api/stat/sites instead of /api/stat/sites


      If i do not modify anything to the script, i have a 404 result.

      If i modify the code
      Code:
      var obj = JSON.parse(value);
      host = obj.host;
      port = obj.port;
      user = obj.user;
      password = obj.password;
      
      var response, login = new HttpRequest();
      login.addHeader('Content-Type: application/x-www-form-urlencoded');
      response = login.post(
        'https://'+host+':'+port+'/api/auth/login',
        '{"username": "'+user+'", "password": "'+password+'"}'
      );
      
      if (login.getStatus() !== 200) {
        throw 'Login failed with status code ' + login.getStatus() + ': ' + response;
      }
      try {
        response = login.get('https://'+host+':'+port+'/proxy/network/api/stat/sites');
        response = JSON.parse(response);
      }
      catch (error) {
        throw 'No JSON Response';
      }
      sites = response.data;
      return JSON.stringify(sites);​
      it returns

      Cannot execute script: Error: cannot get URL: Timeout was reached.
      • at [anon] (httprequest.c:375) internal
      • at [anon] () native strict preventsyield
      • at [anon] (function:12) preventsyield

      Does anyone knows why ?

      Comment


      • spongetort
        spongetort commented
        Editing a comment
        had the same issue... you need to set 'Content-Type: application/json'
    • tikoretech
      Junior Member
      • Dec 2023
      • 10

      #18
      Hey guys!

      It worked until the part where it discovers it on the website, but then it displays the error
      Can't run the script, no Json response, any ideas how to resolve it?​

      Comment

      • tikoretech
        Junior Member
        • Dec 2023
        • 10

        #19
        It's looking like this:

        Click image for larger version

Name:	image.png
Views:	1425
Size:	22.7 KB
ID:	476238
        Attached Files

        Comment

        • jvdb
          Junior Member
          • Feb 2022
          • 23

          #20
          Hi,

          I would like to use it but i get this error:
          Click image for larger version

Name:	image.png
Views:	1412
Size:	21.4 KB
ID:	476534

          Comment

          • michael.weber
            Senior Member
            • Nov 2015
            • 121

            #21
            Helllo jvdb the template is using the Hosts IP Address for the URL:
            Click image for larger version

Name:	image.png
Views:	1448
Size:	35.3 KB
ID:	476549
            Aside form that you need to condfigure the Macros {$UNIFI_USER} {$UNIFI_PASSWORD} and {$UNIFI_PORT}
            Click image for larger version

Name:	image.png
Views:	1459
Size:	35.2 KB
ID:	476550
            Please check this.

            Comment

            • michael.weber
              Senior Member
              • Nov 2015
              • 121

              #22
              tikoretech are you still facing this issue? Sorry for the late response.

              Comment

              • tikoretech
                Junior Member
                • Dec 2023
                • 10

                #23
                Originally posted by michael.weber
                tikoretech are you still facing this issue? Sorry for the late response.
                yes michael... the problem continue...

                Comment

                • michael.weber
                  Senior Member
                  • Nov 2015
                  • 121

                  #24
                  Originally posted by tikoretech

                  yes michael... the problem continue...
                  I found the problem, and I will provide a fix int the github repo until friday

                  Comment

                  • tikoretech
                    Junior Member
                    • Dec 2023
                    • 10

                    #25
                    Originally posted by michael.weber

                    I found the problem, and I will provide a fix int the github repo until friday
                    Show!!! Many thanks for this!!!

                    Comment

                    • jvdb
                      Junior Member
                      • Feb 2022
                      • 23

                      #26
                      hi,

                      I got it working and it's awesome!,
                      Maybe a weird request, we have multiple sites and sometimes we are preparing AP or Switches for our customers, once prepped and provisioned they are taken offline till they are shipped / installed on site.

                      They now show up as offline, we had a script before in Zabbix that filtered the devices were the name started with "#" or "^".

                      Is there a small possibility that device filter can be implemented so we can select or name devices that are prepared or waiting for installation or is there an easy way to implement this ourselfs?

                      Comment

                      • michael.weber
                        Senior Member
                        • Nov 2015
                        • 121

                        #27
                        Originally posted by tikoretech

                        Show!!! Many thanks for this!!!
                        Fixed Version in Github available. Let me know if it is working for you. I added some more "usable" error message now,

                        Comment

                        • michael.weber
                          Senior Member
                          • Nov 2015
                          • 121

                          #28
                          Originally posted by jvdb
                          hi,

                          I got it working and it's awesome!,
                          Maybe a weird request, we have multiple sites and sometimes we are preparing AP or Switches for our customers, once prepped and provisioned they are taken offline till they are shipped / installed on site.

                          They now show up as offline, we had a script before in Zabbix that filtered the devices were the name started with "#" or "^".

                          Is there a small possibility that device filter can be implemented so we can select or name devices that are prepared or waiting for installation or is there an easy way to implement this ourselfs?
                          are you removing the APs from the controller after you configured them? If you remove them, everything should be fine.
                          The number about connected / adopted APs are returned by the UniFi Controller API and these values are not related to any name. So it is not possbile to filter these.
                          If you use different sites I can add a "filter" based on regex for sites to:
                          • Option A: dont create triggers if the names patches the regex
                          • Option B: ignore the whole site
                          Please let me know if I got your problem. If i am wrong please be more detailed

                          Comment

                          • tikoretech
                            Junior Member
                            • Dec 2023
                            • 10

                            #29
                            Originally posted by michael.weber

                            Fixed Version in Github available. Let me know if it is working for you. I added some more "usable" error message now,
                            Thank you very much! 100% resolved, so much so that new alerts started to arrive...

                            Click image for larger version

Name:	image.png
Views:	1412
Size:	26.7 KB
ID:	476656

                            Comment

                            • tikoretech
                              Junior Member
                              • Dec 2023
                              • 10

                              #30
                              michael.weber One question, do I have any alerts if someone connects to a specific network?

                              Comment

                              Working...