Get full_software List From Zabbix Inventory With Python
I have created a Python script which prints out the Zabbix “software_full” inventory field. I used python 3
and the pyzabbix 1.3.0
library. Just add your data to zabbix_server
, username
, password
and group_name
.
As it’s just a quick script for testing, the Zabbix user password is only stored as plaintext. I wouldn’t recommend using it this way regularly, but if you want, be sure to set the right permissions on the script and only use a Zabbix user with as much read permission as needed. You could also use a Python environment variable.
If I get back to that particular script, I’ll make sure to update it, so it uses the Zabbix API tokens.
from pyzabbix import ZabbixAPI
# Function to retrieve data from the "software full" inventory field
def get_software_full_data(host):
if 'inventory' in host and 'software_full' in host['inventory']:
software_full_data = host['inventory']['software_full']
return software_full_data
return None
# Zabbix server information
zabbix_server = 'http://your_zabbix_server/zabbix' # Replace with your Zabbix server address
username = 'your_username' # Replace with your user name
password = 'your_password' # Replace with your user password
# Connect to Zabbix
zapi = ZabbixAPI(zabbix_server)
zapi.login(username, password)
# Specify the group name
group_name = 'Inventory' # Replace with your desired group name
# Get group ID by name
group = zapi.hostgroup.get(filter={"name": group_name})
if group:
group_id = group[0]['groupid']
# Fetch hosts in the specified group
hosts = zapi.host.get(groupids=group_id, output=['hostid', 'host'], selectInventory=["software_full"])
if hosts:
print(f"Hosts in the group '{group_name}':")
for host in hosts:
print(f"Host: {host['host']}")
software_full = get_software_full_data(host)
if software_full:
print(f"Software Full Data:")
print(software_full)
else:
print(f"No 'software full' data found for this host.")
print("-------------------")
else:
print(f"No hosts found in the group '{group_name}'.")
else:
print(f"Group '{group_name}' not found.")
# Logout from Zabbix
zapi.user.logout()