From ec131564f23f34ed23b71bc31a9f08d7e2939fb3 Mon Sep 17 00:00:00 2001 From: Julian P Samaroo Date: Thu, 9 Aug 2018 15:55:16 -0500 Subject: [PATCH 1/5] Updates for Julia 0.7 Replaced (deprecated) Requests.jl with HTTP.jl Updated syntax for 0.7, should be ready for 1.0 --- REQUIRE | 2 +- src/Zabbix.jl | 42 ++++++++++++++++++++---------------------- test/runtests.jl | 2 +- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/REQUIRE b/REQUIRE index e4e7a81..0d79ff1 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,3 +1,3 @@ julia 0.6 -Requests +HTTP JSON diff --git a/src/Zabbix.jl b/src/Zabbix.jl index a2fae29..27656fe 100644 --- a/src/Zabbix.jl +++ b/src/Zabbix.jl @@ -1,9 +1,7 @@ -__precompile__() - module Zabbix # Imports -using Requests +using HTTP using JSON """ @@ -18,7 +16,7 @@ ZabbixAPI("http://SERVER_URL/zabbix/api_jsonrpc.php", "USERNAME", "PASSWORD", tr Here the verbosity is set to true by default. You may wish to set up by passing false instead of true. """ -type ZabbixAPI +mutable struct ZabbixAPI # To be supplied fields server_url::String @@ -69,11 +67,11 @@ function api_version(z::ZabbixAPI) json_data = JSON.json(dict_data) # requests data from zabbix - if verbose info("Hitting $(z.server_url) ...") end - output = Requests.post(z.server_url,data=json_data,headers=z.headers) + if verbose @info("Hitting $(z.server_url) ...") end + output = HTTP.post(z.server_url,body=json_data,headers=z.headers) # return response - convert(VersionNumber, JSON.parse(convert(String, output.data))["result"]) + VersionNumber(JSON.parse(String(output.body))["result"]) end @@ -104,11 +102,11 @@ function auth_token(z::ZabbixAPI) json_data = JSON.json(dict_data) # requests data from zabbix - if verbose info("Hitting $(z.server_url) ...") end - output = Requests.post(z.server_url,data=json_data,headers=z.headers) + if verbose @info("Hitting $(z.server_url) ...") end + output = HTTP.post(z.server_url,body=json_data,headers=z.headers) # return token - JSON.parse(convert(String, output.data))["result"] + JSON.parse(String(output.body))["result"] end @@ -140,7 +138,7 @@ function get_all_hosts(z::ZabbixAPI) verbose = z.verbose # get token - if verbose info("Getting authentication token ... ") end + if verbose @info("Getting authentication token ... ") end token = auth_token(z) # construct data @@ -149,11 +147,11 @@ function get_all_hosts(z::ZabbixAPI) json_data = JSON.json(dict_data) # requests data from zabbix - if verbose info("Hitting $(z.server_url) ...") end - output = Requests.post(z.server_url,data=json_data,headers=z.headers) + if verbose @info("Hitting $(z.server_url) ...") end + output = HTTP.post(z.server_url,body=json_data,headers=z.headers) # return token - JSON.parse(convert(String, output.data)) + JSON.parse(String(output.body)) end @@ -272,28 +270,28 @@ INFO: Updating request id for next API call ... """ function make_request(z::ZabbixAPI, method::String, params=Dict()) verbose = z.verbose - + if method == "apiinfo.version" && params == Dict() return api_version(z) else # get token - if verbose info("Getting authentication token ... ") end + if verbose @info("Getting authentication token ... ") end token = auth_token(z) - + # construct data dict_data = Dict("jsonrpc"=>z.jsonrpc,"id"=>z.id,"method"=>method,"auth"=>token,"params"=>params) json_data = JSON.json(dict_data) # requests data from zabbix - if verbose info("Hitting $(z.server_url) ...") end - output = Requests.post(z.server_url,data=json_data,headers=z.headers) + if verbose @info("Hitting $(z.server_url) ...") end + output = HTTP.post(z.server_url,body=json_data,headers=z.headers) # increment the id for further calls - if verbose info("Updating request id for next API call ...") end + if verbose @info("Updating request id for next API call ...") end setfield!(z,:id, z.id+1) - + # return token - JSON.parse(convert(String, output.data)) + JSON.parse(String(output.body)) end end diff --git a/test/runtests.jl b/test/runtests.jl index 965a55b..53acaab 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,5 @@ using Zabbix -using Base.Test +using Test z = Zabbix.ZabbixAPI("https://www.example.com/zabbix/api_jsonrpc.php","username","password") @test typeof(z) == ZabbixAPI From 27309f94792d9cf62e431a9dd944474a3998afb9 Mon Sep 17 00:00:00 2001 From: Julian P Samaroo Date: Thu, 9 Aug 2018 15:59:41 -0500 Subject: [PATCH 2/5] Changed julia to 0.7 in REQUIRE --- REQUIRE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/REQUIRE b/REQUIRE index 0d79ff1..0a5ab10 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,3 +1,3 @@ -julia 0.6 +julia 0.7 HTTP JSON From 3e4d2f9e41cfa555a3bd94f4207dbac206c28c69 Mon Sep 17 00:00:00 2001 From: Julian P Samaroo Date: Thu, 9 Aug 2018 16:17:36 -0500 Subject: [PATCH 3/5] Change travis to nightly, not sure if extra lines are needed? --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 968b3f2..3b3ad03 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: julia julia: - - 0.6 -script: - - julia -e 'Pkg.clone(pwd()); Pkg.build("Zabbix"); Pkg.test("Zabbix"; coverage=true)'; -after_success: - - julia -e 'cd(Pkg.dir("Zabbix")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'; + - nightly +#script: +# - julia -e 'Pkg.clone(pwd()); Pkg.build("Zabbix"); Pkg.test("Zabbix"; coverage=true)'; +#after_success: +# - julia -e 'cd(Pkg.dir("Zabbix")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'; From 011c3debd39beb601cb8124c1e1f2f74b2d1fc6f Mon Sep 17 00:00:00 2001 From: Julian P Samaroo Date: Thu, 9 Aug 2018 16:21:39 -0500 Subject: [PATCH 4/5] Adding back coverage scripts... --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3b3ad03..2ae08e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: julia julia: - nightly -#script: -# - julia -e 'Pkg.clone(pwd()); Pkg.build("Zabbix"); Pkg.test("Zabbix"; coverage=true)'; -#after_success: -# - julia -e 'cd(Pkg.dir("Zabbix")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'; +script: + - julia -e 'Pkg.clone(pwd()); Pkg.build("Zabbix"); Pkg.test("Zabbix"; coverage=true)'; +after_success: + - julia -e 'cd(Pkg.dir("Zabbix")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'; From fc2c60464fa1c9b227fd67220f1fedbee34ed02c Mon Sep 17 00:00:00 2001 From: Julian P Samaroo Date: Thu, 9 Aug 2018 16:25:42 -0500 Subject: [PATCH 5/5] Need to in Travis script --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2ae08e5..4ac9b3a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,6 @@ language: julia julia: - nightly script: - - julia -e 'Pkg.clone(pwd()); Pkg.build("Zabbix"); Pkg.test("Zabbix"; coverage=true)'; + - julia -e 'using Pkg; Pkg.clone(pwd()); Pkg.build("Zabbix"); Pkg.test("Zabbix"; coverage=true)'; after_success: - - julia -e 'cd(Pkg.dir("Zabbix")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'; + - julia -e 'using Pkg; cd(Pkg.dir("Zabbix")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())';