Ad Widget

Collapse

Complete NOOB...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bostonmacosx
    Junior Member
    • Mar 2013
    • 11

    #1

    Complete NOOB...

    I'm a PHP/MySQL developer with some systems experience.I've been asked to move some data from Zabbix to APEX Oracle for reporting purposes.
    I was going to use the API to grab the data and then just port into our APEX environment.

    Although I understand JSON and PHP I'm having a difficult time finding the list of what.what commands you would use to pull certain data.

    So my two questions are...where is this documentation..I"ve looked at the API documentation and haven't found it....

    #2. Could someone post an example of pulling lets say CPU from a list of systems that I can send into the API.

    Thanks
    Rob
  • ejames
    Junior Member
    • Aug 2011
    • 2

    #2
    Not sure about PHP, but here's a quick shell script to get item data.

    Be sure to change the username/password. Also change the itemid to the item id you're looking for

    TIME_NOW=`date +%s`
    TIME_PAST=$(($TIME_NOW-86400))
    echo $TIME_PAST - $TIME_NOW

    API=http://<zabbix url>/api_jsonrpc.php

    authenticate() {
    curl -s -i -X POST -H 'Content-Type: application/json-rpc' -d "{
    \"params\": {
    \"password\": \"\",
    \"user\": \"\"
    },
    \"jsonrpc\": \"2.0\",
    \"method\": \"user.authenticate\",
    \"auth\": \"\",
    \"id\": 0
    }" $API | grep result | cut -d "\"" -f 8
    }

    AUTH_TOKEN=$(authenticate)

    # GET ITEM HISTORY
    curl -s -i -X POST -H 'Content-Type: application/json-rpc' -d "{
    \"jsonrpc\":\"2.0\",
    \"method\":\"history.get\",
    \"params\":{
    \"history\": 0,
    \"itemids\": [\"42670\"],
    \"time_from\": \"$TIME_PAST\",
    \"output\":\"extend\"
    },
    \"auth\":\"$AUTH_TOKEN\",
    \"id\":2
    }" $API

    Comment

    • heaje
      Senior Member
      Zabbix Certified Specialist
      • Sep 2009
      • 325

      #3
      If you didn't find what you're looking for in the API documentation, it sounds like you want to retrieve actual values from the monitored items that Zabbix watches. That is not possible to do through the API.

      Comment

      • Pavels
        Member
        • Oct 2011
        • 83

        #4
        You can retrieve all of the gathered monitoring data using the history API

        Comment

        • heaje
          Senior Member
          Zabbix Certified Specialist
          • Sep 2009
          • 325

          #5
          pavels- thanks for pointing out that I was wrong. how have I missed that for the last several months in my API usage?

          Comment

          • Pavels
            Member
            • Oct 2011
            • 83

            #6
            Originally posted by heaje
            pavels- thanks for pointing out that I was wrong. how have I missed that for the last several months in my API usage?
            We've completely edited almost all of the API docs, so you might want to check out what else you may have missed

            Comment

            • bostonmacosx
              Junior Member
              • Mar 2013
              • 11

              #7
              So I got to the point of:

              Code:
              $now = time();
              $thirtyago = $now-(60*30);
              $content3 = '{
              	"jsonrpc":"2.0",
              	"method":"history.get",
              	"params":{
              		"history":"0",
              	"output":"extend",
              	"hostids":[10047],
              	"time_from":'.$thirtyago.',
              	"time_to":'.$now.'
              	},
              	"auth":"XXXXXXX",
              	"id":"2"
              }';
              and I get in return:

              Code:
              {"jsonrpc":"2.0","result":[{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373547","value":"459876.9470","ns":"423356642"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373552","value":"429146.4788","ns":"964138444"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373557","value":"388912.1504","ns":"714332024"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373562","value":"431016.5116","ns":"503450177"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373568","value":"383836.4522","ns":"11467948"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373572","value":"434093.7263","ns":"924512922"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373577","value":"450269.2578","ns":"937506727"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373582","value":"555451.6742","ns":"602164555"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373587","value":"492083.1586","ns":"169091833"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373592","value":"373219.6908","ns":"724795487"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373597","value":"342221.0086","ns":"989542404"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373602","value":"439086.2078","ns":"740739237"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373607","value":"462625.9894","ns":"298081557"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373612","value":"440243.1947","ns":"598610965"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373617","value":"427180.9388","ns":"401840261"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373622","value":"450396.8377","ns":"95712027"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373627","value":"407090.5860","ns":"439095231"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373632","value":"395869.5836","ns":"902361644"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373637","value":"459910.6678","ns":"653953971"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373642","value":"500753.2206","ns":"748281666"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373647","value":"505608.9653","ns":"261848783"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373652","value":"372347.9030","ns":"964005242"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373657","value":"410814.3551","ns":"610001606"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373662","value":"452220.4023","ns":"379052248"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373667","value":"380406.2231","ns":"981857541"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373672","value":"491946.3589","ns":"269207090"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373677","value":"436467.9883","ns":"66106419"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373682","value":"380344.2815","ns":"897909624"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373687","value":"433779.3861","ns":"799763119"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373692","value":"438059.8451","ns":"610546448"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373697","value":"448213.1498","ns":"225232565"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373702","value":"457175.3684","ns":"877258415"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373707","value":"499508.8690","ns":"576894689"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373713","value":"401681.6859","ns":"80795110"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373717","value":"415372.0358","ns":"337396055"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373722","value":"446407.4756","ns":"24391937"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373727","value":"414180.2888","ns":"58472641"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373732","value":"418347.4268","ns":"601819753"},{"hosts":[{"hostid":"10047"}],"itemid":"22192","clock":"1363373737","value":"443589.6064","ns":"454512352"},{"hosts":
              so how can I get just information back like # of CPUs Hard Disk and the like.

              Thanks
              Rob

              Comment

              • bostonmacosx
                Junior Member
                • Mar 2013
                • 11

                #8
                Is this working? I posted awhile ago and don't see the reponse.

                Comment

                • tchjts1
                  Senior Member
                  • May 2008
                  • 1605

                  #9
                  Originally posted by bostonmacosx
                  Is this working? I posted awhile ago and don't see the reponse.
                  Anyone with less than 3 posts must have their posts manually approved. This is due to the amount of spam that tries to come through the system.

                  When you submitted your post, you should have seen a message that your post needs to be approved before it will show in the forum.

                  Comment

                  • Pavels
                    Member
                    • Oct 2011
                    • 83

                    #10
                    so how can I get just information back like # of CPUs Hard Disk and the like.
                    Create an item to monitor the value you need and then just request the history for this specific item using the history.get "itemids" parameter.

                    Comment

                    • bostonmacosx
                      Junior Member
                      • Mar 2013
                      • 11

                      #11
                      Sorry just learning here...is there a fixed list of ITEM ids?

                      Comment

                      • Pavels
                        Member
                        • Oct 2011
                        • 83

                        #12
                        No, items are created in the Zabbix frontend. You can find out more about using items in the docs:

                        Comment

                        Working...