zabbix api get value of item 24 hours ago from current timeHow to get the current time in PythonGet current time in milliseconds in Python?Get unique values from a list in pythonHow to get graph value from Zabbix APIGet values with Zabbix web scenarioHow to create graph from log item in zabbix?get host list from zabbix api with pythonGetting values from zabbix history using zabbix apiMonitor multiple values within one Item in ZabbixZabbix 2.2 API get Trigger history

diff shows a file that does not exist

Why does the autopilot disengage even when it does not receive pilot input?

Cubic programming and beyond?

Why does Hellboy file down his horns?

Credit union holding car note, refuses to provide details of how payments have been applied

Science writing - exact, precise, or accurate

Replacements for swear words

Who Can Help Retag This?

Why are Hobbits so fond of mushrooms?

Repeating redundant information after dialogues, to avoid or not?

Supporting developers who insist on using their pet language

What's the minimum number of sensors for a hobby GPS waypoint-following UAV?

Did any of the founding fathers anticipate Lysander Spooner's criticism of the constitution?

Does Google Maps take into account hills/inclines for route times?

Are there any double stars that I can actually see orbit each other?

I have a ruthless DM and I'm considering leaving the party. What are my options to minimize the negative impact to the rest of the group?

Redirect https to fqdn

As a DM, how to avoid unconscious metagaming when dealing with a high AC character?

Why is dry soil hydrophobic? Bad gardener paradox

Can I call 112 to check a police officer's identity in the Czech Republic?

Returning the argument of a function if the argument is not of the right type

Is this floating-point optimization allowed?

How did the hit man miss?

If a specific mass of air is polluted, will the pollution stick with it?



zabbix api get value of item 24 hours ago from current time


How to get the current time in PythonGet current time in milliseconds in Python?Get unique values from a list in pythonHow to get graph value from Zabbix APIGet values with Zabbix web scenarioHow to create graph from log item in zabbix?get host list from zabbix api with pythonGetting values from zabbix history using zabbix apiMonitor multiple values within one Item in ZabbixZabbix 2.2 API get Trigger history






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















Im working on a python script that does some analysis. This script uses the following zabbix api to get the last value of an item:



getlastvalue = 
"jsonrpc":"2.0",
"method":"item.get",
"params":
"output":"extend",
"hostids":"10084",
"search":
"key_":"vfs.fs.size[/var/log,used]"
,
"sortfield":"name"
,
"auth":mytoken,
"id":1



My script analyzes the response and produces this feedback:



LatestValue:499728384 LatestValueEpoch:1553573850 HowLongAgo:33secs ItemID:51150


Now, I wish to know what the value of the item was 24 hours ago...meaning 24 hours from the LatestValueEpoch time. This is where Im having an issue. I think I may not be using the right json. But here's what I've been using:



historyget = 
"jsonrpc":"2.0",
"method":"history.get",
"params":
"output":[
"itemid",
"extend"
],
"time_from":"",
"time_to":"",
"itemids":[
"51150"
]
,
"auth":mytoken,
"id":1



I replace the value of time_from and time_to in my script to reflect yesterday's time (24 hours ago exactly from the current time). But the response I get isnt what I want. What am i doing wrong here?










share|improve this question






























    0















    Im working on a python script that does some analysis. This script uses the following zabbix api to get the last value of an item:



    getlastvalue = 
    "jsonrpc":"2.0",
    "method":"item.get",
    "params":
    "output":"extend",
    "hostids":"10084",
    "search":
    "key_":"vfs.fs.size[/var/log,used]"
    ,
    "sortfield":"name"
    ,
    "auth":mytoken,
    "id":1



    My script analyzes the response and produces this feedback:



    LatestValue:499728384 LatestValueEpoch:1553573850 HowLongAgo:33secs ItemID:51150


    Now, I wish to know what the value of the item was 24 hours ago...meaning 24 hours from the LatestValueEpoch time. This is where Im having an issue. I think I may not be using the right json. But here's what I've been using:



    historyget = 
    "jsonrpc":"2.0",
    "method":"history.get",
    "params":
    "output":[
    "itemid",
    "extend"
    ],
    "time_from":"",
    "time_to":"",
    "itemids":[
    "51150"
    ]
    ,
    "auth":mytoken,
    "id":1



    I replace the value of time_from and time_to in my script to reflect yesterday's time (24 hours ago exactly from the current time). But the response I get isnt what I want. What am i doing wrong here?










    share|improve this question


























      0












      0








      0








      Im working on a python script that does some analysis. This script uses the following zabbix api to get the last value of an item:



      getlastvalue = 
      "jsonrpc":"2.0",
      "method":"item.get",
      "params":
      "output":"extend",
      "hostids":"10084",
      "search":
      "key_":"vfs.fs.size[/var/log,used]"
      ,
      "sortfield":"name"
      ,
      "auth":mytoken,
      "id":1



      My script analyzes the response and produces this feedback:



      LatestValue:499728384 LatestValueEpoch:1553573850 HowLongAgo:33secs ItemID:51150


      Now, I wish to know what the value of the item was 24 hours ago...meaning 24 hours from the LatestValueEpoch time. This is where Im having an issue. I think I may not be using the right json. But here's what I've been using:



      historyget = 
      "jsonrpc":"2.0",
      "method":"history.get",
      "params":
      "output":[
      "itemid",
      "extend"
      ],
      "time_from":"",
      "time_to":"",
      "itemids":[
      "51150"
      ]
      ,
      "auth":mytoken,
      "id":1



      I replace the value of time_from and time_to in my script to reflect yesterday's time (24 hours ago exactly from the current time). But the response I get isnt what I want. What am i doing wrong here?










      share|improve this question
















      Im working on a python script that does some analysis. This script uses the following zabbix api to get the last value of an item:



      getlastvalue = 
      "jsonrpc":"2.0",
      "method":"item.get",
      "params":
      "output":"extend",
      "hostids":"10084",
      "search":
      "key_":"vfs.fs.size[/var/log,used]"
      ,
      "sortfield":"name"
      ,
      "auth":mytoken,
      "id":1



      My script analyzes the response and produces this feedback:



      LatestValue:499728384 LatestValueEpoch:1553573850 HowLongAgo:33secs ItemID:51150


      Now, I wish to know what the value of the item was 24 hours ago...meaning 24 hours from the LatestValueEpoch time. This is where Im having an issue. I think I may not be using the right json. But here's what I've been using:



      historyget = 
      "jsonrpc":"2.0",
      "method":"history.get",
      "params":
      "output":[
      "itemid",
      "extend"
      ],
      "time_from":"",
      "time_to":"",
      "itemids":[
      "51150"
      ]
      ,
      "auth":mytoken,
      "id":1



      I replace the value of time_from and time_to in my script to reflect yesterday's time (24 hours ago exactly from the current time). But the response I get isnt what I want. What am i doing wrong here?







      python json zabbix






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 27 at 10:52









      Duc Nguyen

      93 bronze badges




      93 bronze badges










      asked Mar 26 at 4:46









      Dev OpsDev Ops

      245 bronze badges




      245 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          1














          You have to use the history.get API call.



          Using a combination of time_from, time_till and limit you should get an array of values or a single value accordingly.



          Important: You have to specify the history parameter (History object types to return) in the history.get call: I usually make an item.get to catch the stuff I need, then an history.get.



          A small python sample I wrote as a helper:



          #!/usr/bin/env python
          # -*- coding: utf-8 -*-

          """
          Get history values for specific items in a time range:

          # ./getItemHistoryByName.py -H some-host -I "ICMP response time" -f "26/6/2018 16:00" -t "27/6/2018 23:59"
          ItemID: 77013 - Item: ICMP response time - Key: icmppingsec
          1530021641 26/06/2018 16:00:41 Value: 0.1042
          1530021701 26/06/2018 16:01:41 Value: 0.0993
          1530021762 26/06/2018 16:02:42 Value: 0.1024
          1530021822 26/06/2018 16:03:42 Value: 0.0966
          [cut]
          """

          from zabbix.api import ZabbixAPI
          import sys, argparse
          import time
          import datetime


          zabbixServer = 'http://yourserver/zabbix/'
          zabbixUser = 'someuser'
          zabbixPass = 'somepass'


          def main(argv):
          parser = argparse.ArgumentParser()
          parser.add_argument('-H', required=True, metavar='Hostname')
          parser.add_argument('-I', required=True, metavar='Item Name')
          parser.add_argument('-f', required=True, metavar='From Timestamp')
          parser.add_argument('-t', required=True, metavar='Till Timestamp')

          args = parser.parse_args()


          zapi = ZabbixAPI(url=zabbixServer, user=zabbixUser, password=zabbixPass)

          fromTimestamp = time.mktime(datetime.datetime.strptime(args.f, "%d/%m/%Y %H:%M").timetuple())
          tillTimestamp = time.mktime(datetime.datetime.strptime(args.t, "%d/%m/%Y %H:%M").timetuple())


          f = 'name' : args.I
          items = zapi.item.get(filter=f, host=args.H, output='extend' )

          for item in items:
          print "ItemID: - Item: - Key: ".format(item['itemid'], item['name'], item['key_'])

          values = zapi.history.get(itemids=item['itemid'], time_from=fromTimestamp, time_till=tillTimestamp, history=item['value_type'])

          for historyValue in values:
          currentDate = datetime.datetime.fromtimestamp(int(historyValue['clock'])).strftime('%d/%m/%Y %H:%M:%S')

          print " Value: ".format(historyValue['clock'], currentDate, historyValue['value'])

          if __name__ == "__main__":
          main(sys.argv[1:])





          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55350024%2fzabbix-api-get-value-of-item-24-hours-ago-from-current-time%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            You have to use the history.get API call.



            Using a combination of time_from, time_till and limit you should get an array of values or a single value accordingly.



            Important: You have to specify the history parameter (History object types to return) in the history.get call: I usually make an item.get to catch the stuff I need, then an history.get.



            A small python sample I wrote as a helper:



            #!/usr/bin/env python
            # -*- coding: utf-8 -*-

            """
            Get history values for specific items in a time range:

            # ./getItemHistoryByName.py -H some-host -I "ICMP response time" -f "26/6/2018 16:00" -t "27/6/2018 23:59"
            ItemID: 77013 - Item: ICMP response time - Key: icmppingsec
            1530021641 26/06/2018 16:00:41 Value: 0.1042
            1530021701 26/06/2018 16:01:41 Value: 0.0993
            1530021762 26/06/2018 16:02:42 Value: 0.1024
            1530021822 26/06/2018 16:03:42 Value: 0.0966
            [cut]
            """

            from zabbix.api import ZabbixAPI
            import sys, argparse
            import time
            import datetime


            zabbixServer = 'http://yourserver/zabbix/'
            zabbixUser = 'someuser'
            zabbixPass = 'somepass'


            def main(argv):
            parser = argparse.ArgumentParser()
            parser.add_argument('-H', required=True, metavar='Hostname')
            parser.add_argument('-I', required=True, metavar='Item Name')
            parser.add_argument('-f', required=True, metavar='From Timestamp')
            parser.add_argument('-t', required=True, metavar='Till Timestamp')

            args = parser.parse_args()


            zapi = ZabbixAPI(url=zabbixServer, user=zabbixUser, password=zabbixPass)

            fromTimestamp = time.mktime(datetime.datetime.strptime(args.f, "%d/%m/%Y %H:%M").timetuple())
            tillTimestamp = time.mktime(datetime.datetime.strptime(args.t, "%d/%m/%Y %H:%M").timetuple())


            f = 'name' : args.I
            items = zapi.item.get(filter=f, host=args.H, output='extend' )

            for item in items:
            print "ItemID: - Item: - Key: ".format(item['itemid'], item['name'], item['key_'])

            values = zapi.history.get(itemids=item['itemid'], time_from=fromTimestamp, time_till=tillTimestamp, history=item['value_type'])

            for historyValue in values:
            currentDate = datetime.datetime.fromtimestamp(int(historyValue['clock'])).strftime('%d/%m/%Y %H:%M:%S')

            print " Value: ".format(historyValue['clock'], currentDate, historyValue['value'])

            if __name__ == "__main__":
            main(sys.argv[1:])





            share|improve this answer



























              1














              You have to use the history.get API call.



              Using a combination of time_from, time_till and limit you should get an array of values or a single value accordingly.



              Important: You have to specify the history parameter (History object types to return) in the history.get call: I usually make an item.get to catch the stuff I need, then an history.get.



              A small python sample I wrote as a helper:



              #!/usr/bin/env python
              # -*- coding: utf-8 -*-

              """
              Get history values for specific items in a time range:

              # ./getItemHistoryByName.py -H some-host -I "ICMP response time" -f "26/6/2018 16:00" -t "27/6/2018 23:59"
              ItemID: 77013 - Item: ICMP response time - Key: icmppingsec
              1530021641 26/06/2018 16:00:41 Value: 0.1042
              1530021701 26/06/2018 16:01:41 Value: 0.0993
              1530021762 26/06/2018 16:02:42 Value: 0.1024
              1530021822 26/06/2018 16:03:42 Value: 0.0966
              [cut]
              """

              from zabbix.api import ZabbixAPI
              import sys, argparse
              import time
              import datetime


              zabbixServer = 'http://yourserver/zabbix/'
              zabbixUser = 'someuser'
              zabbixPass = 'somepass'


              def main(argv):
              parser = argparse.ArgumentParser()
              parser.add_argument('-H', required=True, metavar='Hostname')
              parser.add_argument('-I', required=True, metavar='Item Name')
              parser.add_argument('-f', required=True, metavar='From Timestamp')
              parser.add_argument('-t', required=True, metavar='Till Timestamp')

              args = parser.parse_args()


              zapi = ZabbixAPI(url=zabbixServer, user=zabbixUser, password=zabbixPass)

              fromTimestamp = time.mktime(datetime.datetime.strptime(args.f, "%d/%m/%Y %H:%M").timetuple())
              tillTimestamp = time.mktime(datetime.datetime.strptime(args.t, "%d/%m/%Y %H:%M").timetuple())


              f = 'name' : args.I
              items = zapi.item.get(filter=f, host=args.H, output='extend' )

              for item in items:
              print "ItemID: - Item: - Key: ".format(item['itemid'], item['name'], item['key_'])

              values = zapi.history.get(itemids=item['itemid'], time_from=fromTimestamp, time_till=tillTimestamp, history=item['value_type'])

              for historyValue in values:
              currentDate = datetime.datetime.fromtimestamp(int(historyValue['clock'])).strftime('%d/%m/%Y %H:%M:%S')

              print " Value: ".format(historyValue['clock'], currentDate, historyValue['value'])

              if __name__ == "__main__":
              main(sys.argv[1:])





              share|improve this answer

























                1












                1








                1







                You have to use the history.get API call.



                Using a combination of time_from, time_till and limit you should get an array of values or a single value accordingly.



                Important: You have to specify the history parameter (History object types to return) in the history.get call: I usually make an item.get to catch the stuff I need, then an history.get.



                A small python sample I wrote as a helper:



                #!/usr/bin/env python
                # -*- coding: utf-8 -*-

                """
                Get history values for specific items in a time range:

                # ./getItemHistoryByName.py -H some-host -I "ICMP response time" -f "26/6/2018 16:00" -t "27/6/2018 23:59"
                ItemID: 77013 - Item: ICMP response time - Key: icmppingsec
                1530021641 26/06/2018 16:00:41 Value: 0.1042
                1530021701 26/06/2018 16:01:41 Value: 0.0993
                1530021762 26/06/2018 16:02:42 Value: 0.1024
                1530021822 26/06/2018 16:03:42 Value: 0.0966
                [cut]
                """

                from zabbix.api import ZabbixAPI
                import sys, argparse
                import time
                import datetime


                zabbixServer = 'http://yourserver/zabbix/'
                zabbixUser = 'someuser'
                zabbixPass = 'somepass'


                def main(argv):
                parser = argparse.ArgumentParser()
                parser.add_argument('-H', required=True, metavar='Hostname')
                parser.add_argument('-I', required=True, metavar='Item Name')
                parser.add_argument('-f', required=True, metavar='From Timestamp')
                parser.add_argument('-t', required=True, metavar='Till Timestamp')

                args = parser.parse_args()


                zapi = ZabbixAPI(url=zabbixServer, user=zabbixUser, password=zabbixPass)

                fromTimestamp = time.mktime(datetime.datetime.strptime(args.f, "%d/%m/%Y %H:%M").timetuple())
                tillTimestamp = time.mktime(datetime.datetime.strptime(args.t, "%d/%m/%Y %H:%M").timetuple())


                f = 'name' : args.I
                items = zapi.item.get(filter=f, host=args.H, output='extend' )

                for item in items:
                print "ItemID: - Item: - Key: ".format(item['itemid'], item['name'], item['key_'])

                values = zapi.history.get(itemids=item['itemid'], time_from=fromTimestamp, time_till=tillTimestamp, history=item['value_type'])

                for historyValue in values:
                currentDate = datetime.datetime.fromtimestamp(int(historyValue['clock'])).strftime('%d/%m/%Y %H:%M:%S')

                print " Value: ".format(historyValue['clock'], currentDate, historyValue['value'])

                if __name__ == "__main__":
                main(sys.argv[1:])





                share|improve this answer













                You have to use the history.get API call.



                Using a combination of time_from, time_till and limit you should get an array of values or a single value accordingly.



                Important: You have to specify the history parameter (History object types to return) in the history.get call: I usually make an item.get to catch the stuff I need, then an history.get.



                A small python sample I wrote as a helper:



                #!/usr/bin/env python
                # -*- coding: utf-8 -*-

                """
                Get history values for specific items in a time range:

                # ./getItemHistoryByName.py -H some-host -I "ICMP response time" -f "26/6/2018 16:00" -t "27/6/2018 23:59"
                ItemID: 77013 - Item: ICMP response time - Key: icmppingsec
                1530021641 26/06/2018 16:00:41 Value: 0.1042
                1530021701 26/06/2018 16:01:41 Value: 0.0993
                1530021762 26/06/2018 16:02:42 Value: 0.1024
                1530021822 26/06/2018 16:03:42 Value: 0.0966
                [cut]
                """

                from zabbix.api import ZabbixAPI
                import sys, argparse
                import time
                import datetime


                zabbixServer = 'http://yourserver/zabbix/'
                zabbixUser = 'someuser'
                zabbixPass = 'somepass'


                def main(argv):
                parser = argparse.ArgumentParser()
                parser.add_argument('-H', required=True, metavar='Hostname')
                parser.add_argument('-I', required=True, metavar='Item Name')
                parser.add_argument('-f', required=True, metavar='From Timestamp')
                parser.add_argument('-t', required=True, metavar='Till Timestamp')

                args = parser.parse_args()


                zapi = ZabbixAPI(url=zabbixServer, user=zabbixUser, password=zabbixPass)

                fromTimestamp = time.mktime(datetime.datetime.strptime(args.f, "%d/%m/%Y %H:%M").timetuple())
                tillTimestamp = time.mktime(datetime.datetime.strptime(args.t, "%d/%m/%Y %H:%M").timetuple())


                f = 'name' : args.I
                items = zapi.item.get(filter=f, host=args.H, output='extend' )

                for item in items:
                print "ItemID: - Item: - Key: ".format(item['itemid'], item['name'], item['key_'])

                values = zapi.history.get(itemids=item['itemid'], time_from=fromTimestamp, time_till=tillTimestamp, history=item['value_type'])

                for historyValue in values:
                currentDate = datetime.datetime.fromtimestamp(int(historyValue['clock'])).strftime('%d/%m/%Y %H:%M:%S')

                print " Value: ".format(historyValue['clock'], currentDate, historyValue['value'])

                if __name__ == "__main__":
                main(sys.argv[1:])






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 26 at 8:45









                Simone ZabberoniSimone Zabberoni

                8894 silver badges12 bronze badges




                8894 silver badges12 bronze badges
















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55350024%2fzabbix-api-get-value-of-item-24-hours-ago-from-current-time%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript