Ad Widget

Collapse

Zabbix API -- items_to_csv error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • trivi
    Junior Member
    • Nov 2017
    • 4

    #1

    Zabbix API -- items_to_csv error

    Hi,

    I followed the below link and configured zabbix API to fetch the items values into CSV report while when i am trying to run the fetch_items_to_csv.py getting zabbix server is not reachable but zabbix front-end is accessible.



    Could anyone please help me on this.

    Any help would be appreciated.
  • FrankBlack_MX
    Junior Member
    • Apr 2020
    • 1

    #2
    Hi,

    You change the parameter in zabbix_api.py:

    auth = None

    Also change this:

    obj = self.json_obj('user.authenticate', { 'user' : l_user,

    to:

    obj = self.json_obj('user.login', { 'user' : l_user,



    Regards.

    PD Sorry for mi english

    Comment

    • hsyah
      Junior Member
      • Sep 2020
      • 2

      #3
      It is normal to execute the following
      [root@zabbix opt]# ./fetch_items_to_csv.py -s 127.0.0.1 -u admin -p zabbix -n 10.1.1.1
      Only the last value from each key has been fetched, specify t1 or t1 and t2 to fetch more data


      But
      The execution of the following is abnormal and the data cannot be generated

      [root@zabbix opt]# ./fetch_items_to_csv.py -s 127.0.0.1 -u admin -p zabbix -n 10.1.1.1 -t1 '2020-09-01 10:30:00' -t2 '2020-09-01 16:00:00' -v 1

      Traceback (most recent call last):
      File "./fetch_items_to_csv.py", line 179, in <module>
      fetch_to_csv(args.username, args.password, "http://"+args.server_IP+"/zabbix", args.hostname, args.key, args.output, args.datetime1,args.datetime2,args.debuglevel)
      File "./fetch_items_to_csv.py", line 102, in fetch_to_csv
      history = zapi.history.get({"hostids":[hostid,],"time_from":timestamp1,"time_till":timestamp2, "output":"extend" })
      File "/opt/zabbix_api.py", line 304, in wrapper
      return self.do_request(self.json_obj(name,opts))['result']
      File "/opt/zabbix_api.py", line 286, in do_request
      return self.parent.do_request(req)
      File "/opt/zabbix_api.py", line 251, in do_request
      raise ZabbixAPIException(msg,jobj['error']['code'])
      zabbix_api.ZabbixAPIException: (u'Error -32602: Invalid params., Invalid parameter "/time_from": an integer is expected.', -32602)
      [root@zabbix opt]#

      Comment

      • r9paul
        Junior Member
        • Jun 2021
        • 1

        #4
        Originally posted by hsyah
        The execution of the following is abnormal and the data cannot be generated

        [root@zabbix opt]# ./fetch_items_to_csv.py -s 127.0.0.1 -u admin -p zabbix -n 10.1.1.1 -t1 '2020-09-01 10:30:00' -t2 '2020-09-01 16:00:00' -v 1

        Traceback (most recent call last):
        File "./fetch_items_to_csv.py", line 179, in <module>
        fetch_to_csv(args.username, args.password, "http://"+args.server_IP+"/zabbix", args.hostname, args.key, args.output, args.datetime1,args.datetime2,args.debuglevel)
        File "./fetch_items_to_csv.py", line 102, in fetch_to_csv
        history = zapi.history.get({"hostids":[hostid,],"time_from":timestamp1,"time_till":timestamp2, "output":"extend" })
        File "/opt/zabbix_api.py", line 304, in wrapper
        return self.do_request(self.json_obj(name,opts))['result']
        File "/opt/zabbix_api.py", line 286, in do_request
        return self.parent.do_request(req)
        File "/opt/zabbix_api.py", line 251, in do_request
        raise ZabbixAPIException(msg,jobj['error']['code'])
        zabbix_api.ZabbixAPIException: (u'Error -32602: Invalid params., Invalid parameter "/time_from": an integer is expected.', -32602)
        [root@zabbix opt]#
        An old thread, but I was having this same problem and resolved this problem by modifying the fetch_items_to_csv.py slightly to force the date conversion to be an integer,
        For example
        Code:
        71: timestamp1=int(time.mktime(d1.timetuple()))
        72: timestamp2=int(round(time.time()))
        I also used the latest version of the zabbix_api.py taken from https://github.com/gescheit/scripts/.../zabbix_api.py which resolved the old auth issue.

        Comment

        Working...