Update host 'Visible name' and 'Description' from snmp OID, pyzabbix

Prerequsites:
#install pip
curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
python get-pip.py

#upgrade pip
pip install --upgrade pip

#install pizabbix module
pip install pyzabbix

#install snmp module
yum install net-snmp-python
Script:
#!/usr/bin/python
"""
Shows a list of all current issues (AKA tripped triggers)
"""
#add snmp support. this will allow to query name
import netsnmp

#for argument support
import sys

from pyzabbix import ZabbixAPI

# The hostname at which the Zabbix web interface is available
ZABBIX_SERVER = 'http://localhost/zabbix'

zapi = ZabbixAPI(ZABBIX_SERVER)

# Login to the Zabbix API
zapi.login('Admin', 'zabbix')


#zapi.do_request('host.get', { 'filter': {'name': sys.argv[1]}, 'output': 'hostid'})
res1 = zapi.do_request('host.get', { 'filter': {'host': sys.argv[1]}, 'output': 'hostid'})

#show json output
print res1

#calculate only id
res2 = str(res1.get(u'result')).split('\'')

#put id in variable and result it in screen
zabbix_hostid = res2[3]
print res2[3]

#establish snmp session using python library netsnmp
session = netsnmp.Session( DestHost=sys.argv[1], Version=2, Community='ccontrol' )
#query device name
session_name = netsnmp.VarList( netsnmp.Varbind('.1.3.6.1.2.1.1.5.0') )
#query device description
session_desc = netsnmp.VarList( netsnmp.Varbind('.1.3.6.1.2.1.1.6.0') )

#put snmp session into variable
dev_name = session.get(session_name)
dev_desc = session.get(session_desc)

#output plain variable
print dev_name[0]
print dev_desc[0]

#update host 'Visiable name' and 'Description'
zapi.do_request('host.update', {'hostid': zabbix_hostid,'name': dev_name[0],'description': dev_desc[0]})
Related:
https://ben.akrin.com/?p=1234