okand / zabbix-whois-expiry

Monitor expiration dates for domains and get notified when they're about to expire
Other
13 stars 9 forks source link

Error occurred while executing whois() for domain #4

Closed burnout-champion closed 2 years ago

burnout-champion commented 2 years ago

Hello,

I am using this with zabbix 5.4.

As per your very detailed instructions I installed pip3, then through that I ran the command to install py-zabbix & python-whois.

I copied the two scripts in the externalscripts folder, created a new "whois" folder there and copied the example json you have provided. I then changed the domains in that to the ones I wanted to monitor, and renamed the file to what I also named the host in zabbix (plus .json at the end).

After restarting the zabbix server just in case, I first ran the discovery script that worked with no issue and created my domains in zabbix.

The problem is that the second script gives an output of: "Error occurred while executing whois() for" for each domain in my json file.

Do you have any ideas on what I could do to fix this?

Thanks, Mike

okand commented 2 years ago

That error is way too vague for me to say anything I'm afraid.

Edit: Can you uncomment the print statements at the very end of the script and run it manually in the terminal once? Then paste the output here, that might give us something.

burnout-champion commented 2 years ago

Hi and thanks for the quick reply!

I think it is this part of your .py script:

except: print("Error occurred while executing whois() for %s." % domain)

It happens while running the script on cli:

Edit: this is the output with the last parts uncommented:

root@zabbix:/usr/lib/zabbix/externalscripts# ./zabbix-whois-check.py domain-expiry-check Error occurred while executing whois() for domain1.com. Error occurred while executing whois() for domain2.com. Error occurred while executing whois() for domain3.com. { "domain_name": null, "registrar": null, "whois_server": null, "referral_url": null, "updated_date": null, "creation_date": null, "expiration_date": null, "name_servers": null, "status": null, "emails": null, "dnssec": null, "name": null, "org": null, "address": null, "city": null, "state": null, "zipcode": null, "country": null } None None Traceback (most recent call last): File "./zabbix-whois-check.py", line 34, in print(packet) NameError: name 'packet' is not defined

Thanks, Mike

okand commented 2 years ago

Could you try with the old version that just crashes when something goes wrong instead of gracefully telling zabbix that something went wrong?

I don't use this script or even zabbix myself anymore but for example, I just tried it in WSL and it behaves like yours. When trying the old version it instead helpfully tells me that it can't find the zabbix_agent config for zabbix_sender to use, which is correct as I don't have it installed. That might tell us something useful from your end.

https://github.com/okand/zabbix-whois-expiry/blob/d67283a5604b36a3b8e0f9b502b8a2f3a5f83968/zabbix-whois-check.py

burnout-champion commented 2 years ago

Hi, I will give it a go and let you know, thanks.

Do you have the command that does the whois check for the script so I can test it on it's own?

It's a brand new linux server so there might be something missing in its general configuration as I am not a linux admin.

okand commented 2 years ago

That is done with one of the python modules you install at the start. It happens by importing whois on line 10 and then naming and running it on line 21. You then view its result by printing the variable called w by removing the leading # sign on line 32 before running the script. The way it is structured it will only print the last domain listed in your json-file since print(w) comes after the for-loop has already ended.

If you use that old commit of the script that doesn't have the try: except: parts to more gracefully handle errors python will try to print to you exactly what goes wrong instead.

burnout-champion commented 2 years ago

Hi again, I think I found the error,

I tried a whois command for my domain (.gr) and it gives me this: This TLD has no whois server, but you can access the whois database at https://grweb.ics.forth.gr/public/whois

while it gives me a proper result when trying google.com

I also put google.com on the json file and it is reported in Zabbix with no issues, so the problem seems to be with the .gr domains in general (all that I have tried).

If I find a way to get a correct result with a simple whois command, would I be able to modify the code a bit to add that and have the result reported to zabbix as well?

Thanks a lot for you help! Mike

okand commented 2 years ago

It appears to be exactly the same problem I had with .no domains when I first wrote this script years ago (.no works now I noticed though, I should update the readme file). It just lists null for the values we want from the returned results. Code-wise the issue lies somewhere in python-whois instead then which is beyond my control but appears to be handled over here: https://github.com/richardpenman/whois

I can see there are issues about various other TLDs already but I suspect .gr will be more complicated or perhaps not even possible since they appear to not provide standardized whois information at all. You can try this yourself by just running whois example.com and whois forth.gr then compare the results.

alexander@IVER-PF26FMWH:~/code/zabbix-whois-expiry$ whois example.com
   Domain Name: EXAMPLE.COM
   Registry Domain ID: 2336799_DOMAIN_COM-VRSN
   Registrar WHOIS Server: whois.iana.org
   Registrar URL: http://res-dom.iana.org
   Updated Date: 2021-08-14T07:01:44Z
   Creation Date: 1995-08-14T04:00:00Z
   Registry Expiry Date: 2022-08-13T04:00:00Z
   Registrar: RESERVED-Internet Assigned Numbers Authority
   Registrar IANA ID: 376
   Registrar Abuse Contact Email:
   Registrar Abuse Contact Phone:
   Domain Status: clientDeleteProhibited https://icann.org/epp#clientDeleteProhibited
   Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited
   Domain Status: clientUpdateProhibited https://icann.org/epp#clientUpdateProhibited
   Name Server: A.IANA-SERVERS.NET
   Name Server: B.IANA-SERVERS.NET
   DNSSEC: signedDelegation
   DNSSEC DS Data: 31589 8 1 3490A6806D47F17A34C29E2CE80E8A999FFBE4BE
   DNSSEC DS Data: 31589 8 2 CDE0D742D6998AA554A92D890F8184C698CFAC8A26FA59875A990C03E576343C
   DNSSEC DS Data: 43547 8 1 B6225AB2CC613E0DCA7962BDC2342EA4F1B56083
   DNSSEC DS Data: 43547 8 2 615A64233543F66F44D68933625B17497C89A70E858ED76A2145997EDF96A918
   DNSSEC DS Data: 31406 8 1 189968811E6EBA862DD6C209F75623D8D9ED9142
   DNSSEC DS Data: 31406 8 2 F78CF3344F72137235098ECBBD08947C2C9001C7F6A085A17F518B5D8F6B916D
   URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/
>>> Last update of whois database: 2021-09-28T12:04:11Z <<<

For more information on Whois status codes, please visit https://icann.org/epp

NOTICE: **bunch of extra output removed**

alexander@IVER-PF26FMWH:~/code/zabbix-whois-expiry$ whois forth.gr
This TLD has no whois server, but you can access the whois database at
https://grweb.ics.forth.gr/public/whois