Closed Borosan closed 1 year ago
grep -i url /usr/local/lib/python3.8/site-packages/zabbix_api.py -n
37:# import urllib2 39:# import urllib.request as urllib2 # python3 40:import urllib.request as urllib2 # python3 113: url = '/api_jsonrpc.php' 142: self.url = server + '/api_jsonrpc.php' 152: self.debug(logging.INFO, "url: " + self.url) 247: request = urllib2.Request(url=self.url, data=json_obj.encode('utf-8'), headers=headers) 250: https_handler = urllib2.HTTPSHandler(debuglevel=0, context=_create_unverified_context()) 252: https_handler = urllib2.HTTPSHandler(debuglevel=0) 253: opener = urllib2.build_opener(https_handler) 255: http_handler = urllib2.HTTPHandler(debuglevel=0) 256: opener = urllib2.build_opener(http_handler) 260: urllib2.install_opener(opener) 269: except urllib2.URLError as e: 274: raise ZabbixAPIException("urllib2.URLError - %s" % e)
I bet 'Not Found' means that the web server returns 404 Not found.
Try changing your URL to http://zab.example.com/zabbix
If it fails too then what do you get when you execute
curl -v -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method":"apiinfo.version","params":[],"id":1}' "http://zab.example.com/api_jsonrpc.php"
Thank you . You were right :) the problem resolve by changing zabbix url from "zab.example.com" to "zab.example.com/zabbix"
SUMMARY
Hello everyone, i am trying to automatically add zabbix host using ansible from my jenkins(or any other host)
ISSUE TYPE
bug / error / versions problems or mismatch
COMPONENT NAME
zabbix-api ---> ZabbixAPI ---> zabbix-host
ANSIBLE VERSION
ansible [core 2.12.2] config file = /etc/ansible/ansible.cfg configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.8/site-packages/ansible ansible collection location = /home/ansible/.ansible/collections:/usr/share/ansible/collections executable location = /usr/bin/ansible python version = 3.8.12 (default, May 10 2022, 23:46:40) [GCC 8.5.0 20210514 (Red Hat 8.5.0-10)] jinja version = 2.10.3 libyaml = True
os version
Rocky Linux release 8.6 (Green Obsidian)
python version
Python 3.8.12
pip3 installed
pip3 list installed Package Version
ansible 5.4.0 ansible-core 2.12.2 asn1crypto 1.2.0 Babel 2.7.0 certifi 2022.9.24 cffi 1.13.2 charset-normalizer 2.1.1 cryptography 2.8 idna 2.8 Jinja2 2.10.3 MarkupSafe 1.1.1 packaging 21.3 pip 19.3.1 ply 3.11 pycparser 2.19 pyparsing 3.0.9 pytz 2019.3 PyYAML 5.4.1 pyzabbix 1.2.1 requests 2.28.1 resolvelib 0.5.4 setuptools 41.6.0 six 1.12.0 urllib3 1.26.12 zabbix-api 0.5.4
ansible galaxy collection list
ansible-galaxy collection list
/usr/lib/python3.8/site-packages/ansible_collections Collection Version
amazon.aws 2.1.0 ansible.netcommon 2.5.1 ansible.posix 1.3.0 ansible.utils 2.5.0 ansible.windows 1.9.0 arista.eos 3.1.0 awx.awx 19.4.0 azure.azcollection 1.11.0 check_point.mgmt 2.2.2 chocolatey.chocolatey 1.2.0 cisco.aci 2.1.0 cisco.asa 2.1.0 cisco.intersight 1.0.18 cisco.ios 2.7.1 cisco.iosxr 2.7.0 cisco.ise 1.2.1 cisco.meraki 2.6.0 cisco.mso 1.3.0 cisco.nso 1.0.3 cisco.nxos 2.9.0 cisco.ucs 1.6.0 cloud.common 2.1.0 cloudscale_ch.cloud 2.2.0 community.aws 2.3.0 community.azure 1.1.0 community.ciscosmb 1.0.4 community.crypto 2.2.2 community.digitalocean 1.15.1 community.dns 2.0.7 community.docker 2.2.0 community.fortios 1.0.0 community.general 4.5.0 community.google 1.0.0 community.grafana 1.3.2 community.hashi_vault 2.3.0 community.hrobot 1.2.2 community.kubernetes 2.0.1 community.kubevirt 1.0.0 community.libvirt 1.0.2 community.mongodb 1.3.2 community.mysql 2.3.4 community.network 3.0.0 community.okd 2.1.0 community.postgresql 1.7.0 community.proxysql 1.3.1 community.rabbitmq 1.1.0 community.routeros 2.0.0 community.skydive 1.0.0 community.sops 1.2.0 community.vmware 1.17.1 community.windows 1.9.0 containers.podman 1.9.1 cyberark.conjur 1.1.0 cyberark.pas 1.0.13 dellemc.enterprise_sonic 1.1.0 dellemc.openmanage 4.4.0 dellemc.os10 1.1.1 dellemc.os6 1.0.7 dellemc.os9 1.0.4 f5networks.f5_modules 1.14.0 fortinet.fortimanager 2.1.4 fortinet.fortios 2.1.4 frr.frr 1.0.3 gluster.gluster 1.0.2 google.cloud 1.0.2 hetzner.hcloud 1.6.0 hpe.nimble 1.1.4 ibm.qradar 1.0.3 infinidat.infinibox 1.3.3 infoblox.nios_modules 1.2.1 inspur.sm 1.3.0 junipernetworks.junos 2.9.0 kubernetes.core 2.2.3 mellanox.onyx 1.0.0 netapp.aws 21.7.0 netapp.azure 21.10.0 netapp.cloudmanager 21.14.0 netapp.elementsw 21.7.0 netapp.ontap 21.16.0 netapp.storagegrid 21.9.0 netapp.um_info 21.8.0 netapp_eseries.santricity 1.2.13 netbox.netbox 3.5.1 ngine_io.cloudstack 2.2.3 ngine_io.exoscale 1.0.0 ngine_io.vultr 1.1.0 openstack.cloud 1.7.0 openvswitch.openvswitch 2.1.0 ovirt.ovirt 1.6.6 purestorage.flasharray 1.12.1 purestorage.flashblade 1.9.0 sensu.sensu_go 1.13.0 servicenow.servicenow 1.0.6 splunk.es 1.0.2 t_systems_mms.icinga_director 1.27.1 theforeman.foreman 2.2.0 vyos.vyos 2.7.0 wti.remote 1.0.3
/home/ansible/.ansible/collections/ansible_collections Collection Version
ansible.netcommon 4.0.0 ansible.posix 1.4.0 ansible.utils 2.6.1 ansible.windows 1.11.1 community.general 5.7.0 community.mysql 3.5.1 community.postgresql 2.2.0 community.zabbix 1.8.0
CONFIGURATION
my play book:
name: Add Zabbix Host hosts: localhost collections:
tasks:
EXPECTED RESULTS
running ansible playbook with no errors and having my host added to zabbix server
ACTUAL RESULTS
ansible-playbook cust2-playbook.yaml [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAY [Add Zabbix Host] *****
TASK [Gathering Facts] ***** ok: [localhost]
TASK [Add Host] **** fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to connect to Zabbix server: urllib2.URLError - Not Found"}
PLAY RECAP ***** localhost : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0