zbx-sadman / unifi_miner

UniFi Miner helps deliver data from UniFi Controller to Zabbix
66 stars 11 forks source link

No error messages when LWP::Protocol::https is not installed #20

Open fraternl opened 3 years ago

fraternl commented 3 years ago

It took me a while before I got it working and hopefully you will modify your code so others don't have the same problem. The reason why it didn't work out of the box for me is probably because I started with a fresh perl installation from source. On this server there's also other software and it has perl pre-installed. I installed a fresh perl in /usr/local/bin

I modified /usr/local/sbin/unifi_miner.pl so it has the credentials in the code and also modified the first line to

!/usr/local/bin/perl

I then executed _unifiminer.pl and I saw I needed to install some perl modules which I did with CPAN until I didn't get any errors. I then started unifi_miner.pl again and it just gave me this

unifi_miner.pl

{
   "data" : []
}

It wasn't until I enabled DEBUG until I found what was going on.....

unifi_miner.pl 
[18046] 2021-02-18 22:52:59 [+] fetchData() started
[18046] 2021-02-18 22:52:59 [+] fetchDataFromController() started
[18046] 2021-02-18 22:52:59 [>]  args: object path: 'https://127.0.0.1:8443/api/self/sites'
[18046] 2021-02-18 22:52:59 [!] Comminication error: '501 Protocol scheme 'https' is not supported (LWP::Protocol::https not installed)'

[18046] 2021-02-18 22:52:59 [!] Can't fetch data from controller
[18046] 2021-02-18 22:52:59 [*] Logout from UniFi controller
{
   "data" : []
}

That was easy to fix, but it took a long time before I enabled debug.

Can you please change the code accordingly so this kind of error gets any feedback. The code could also test for LWP::Protocol::https

zbx-sadman commented 3 years ago

Yes, i think that error message on Zabbix side should be helpful, but how to deliver it to Z?

UPD. I can just make little change in the manual: "Install necessary Perl modules ...liblwp-protocol-https-perl "...

fraternl commented 3 years ago

it's just when you're setting it up. I didn't even know there was an api and at that point i had no time yet to learn the syntax of the miner.

I write a lot of this stuff myself and would never expect that a fatal error like this would not throw an error. You can throw it out on the error output.

I just hoped to be a bit wiser when I enabled debug. It was a surprise for me that the error was fatal even though it returned syntactically correct data.

It would have been better if it just crashed :)

I'm very glad you made it, though.

cheers