check-eos-watchdoggiee
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -14,8 +14,19 @@ #!/usr/bin/env node | ||
.version(pkg.version, '-v, --version') | ||
.option('-u, --url [message]', 'Set url of API endpoint') | ||
.option('-p, --key-provider [message]', 'Set keyProvider for eosjs') | ||
.option('-k, --key [message]', 'Set key for contract data') | ||
.option('-u, --url [message]', 'Set httpEndpoint for eosjs') | ||
.option('-a, --account [message]', 'Set account name for eosjs contract execution') | ||
.option('-u, --url [message]', 'Set httpEndpoint for eosjs') | ||
.option('-c, --chain [message]', 'Set chainId for eosjs') | ||
.option('-t, --time [message]', 'Set MAX time for request') | ||
.parse(process.argv); | ||
if (program.url){ | ||
if (program.account && program.keyProvider && program.key && program.time){ | ||
watchdoggiee.check_eos_watchdoggiee({ | ||
url: program.url | ||
url: program.url, | ||
chain: program.chain, | ||
key: program.key, | ||
keyProvider: program.keyProvider, | ||
account: program.account, | ||
time: program.time | ||
}, (err, result) => { | ||
@@ -27,2 +38,4 @@ if (err){ | ||
}); | ||
} else { | ||
console.error("Please check your command line flags!".yellow); | ||
} |
@@ -9,12 +9,22 @@ /* | ||
const https = require("https"); | ||
const eosjs = require("eosjs"); | ||
const endpoint = "/v1/chain/get_info"; | ||
const defWarn = 2.0; | ||
const defCrit = 10.0; | ||
const contract = "watchdoggiee"; | ||
let configEOS = { | ||
chainId: "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906", // jungle 038f4b0fc8ff18a4f0842a8f0564611f6e96e8535901dd45e43ac8691a1c4dca | ||
httpEndpoint: "https://bp.cryptolions.io", // jungle http://jungle.cryptolions.io:18888 | ||
keyProvider: "", | ||
expireInSeconds: 10, | ||
broadcast: true, | ||
debug: false, | ||
sign: true | ||
}; | ||
let customFunctions = {}; | ||
process.on('uncaughtException', (err) => { | ||
console.error(`======= UncaughtException: ${err}`); | ||
}); | ||
customFunctions.check_eos_watchdoggiee = (options, callback) => { | ||
let warn = Number(options.warn) || defWarn; | ||
let crit = Number(options.crit) || defCrit; | ||
let request = (options.url.indexOf("https") >= 0) ? https : http; | ||
@@ -26,34 +36,67 @@ let slash = options.url[options.url.length - 1]; | ||
request.get(url + endpoint, (res) => { | ||
let data = ""; | ||
res.on("data", (chunk) => { | ||
data += chunk; | ||
}); | ||
res.on("end", () => { | ||
let parsed = {}; | ||
try{ | ||
parsed = JSON.parse(data); | ||
} catch(e){ | ||
callback(`${e}`.red); | ||
} | ||
let diff = (+new Date() - timeStart) / 1000; | ||
let status = 'OK'; | ||
let color = 'cyan'; | ||
if( diff > crit ){ | ||
status = 'CRITICAL'; | ||
color = 'red'; | ||
} else if( diff > warn ){ | ||
status = 'WARNING'; | ||
color = 'yellow'; | ||
} | ||
let result = `BLOCKTIME ${status} - ${diff}s difference|time_diff=${diff}\n`[color]; | ||
callback(null, result); | ||
}); | ||
}).on("error", (err) => { | ||
callback(`${err.message}`.red); | ||
configEOS.httpEndpoint = url || configEOS.httpEndpoint; | ||
configEOS.chainId = options.chain || configEOS.chainId; | ||
configEOS.keyProvider = options.keyProvider; | ||
let eos = new eosjs(configEOS); | ||
eos.contract(contract).then(myaccount => { | ||
myaccount.setkv(options.account, options.key, +new Date(), | ||
{ authorization: `${options.account}@watchdog`, | ||
broadcast: true, | ||
sign: true | ||
}, | ||
(err, result) => { | ||
if (err){ | ||
return callback(err); | ||
} | ||
//console.log(result); | ||
let timeMAX = +new Date() + options.time * 1000; | ||
checkReqTime(timeMAX, callback); | ||
}); | ||
}); | ||
function checkReqTime(timeMAX, callback){ | ||
eos.getTableRows({ | ||
json: true, | ||
code: contract, | ||
scope: options.account, | ||
table: "kvs", | ||
table_key: "string", | ||
lower_bound: "0", | ||
upper_bound: "-1", | ||
limit: 100 | ||
}) | ||
.then(result => { | ||
if (result && result.rows){ | ||
let diff = null; | ||
let date = +new Date(); | ||
result.rows.forEach(elem => { | ||
if (`${elem.key}` === options.key){ | ||
diff = (Number(elem.val) - +new Date(elem.ts)) / 1000; | ||
} | ||
}); | ||
if (diff){ | ||
return callback(null, `REQTIME OK - ${diff} s difference|time_diff=${diff}\n`.cyan); | ||
} | ||
if (!diff && timeMAX < date){ | ||
return callback(`REQTIME CRYTICAL >${options.time} difference|time_diff > ${options.time}\n`.red); | ||
} | ||
checkReqTime(eos, options, timeStart, callback); | ||
} else { | ||
console.error('Result get Error'); | ||
checkReqTime(eos, options, timeStart, callback); | ||
} | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
checkReqTime(eos, options, timeStart, callback); | ||
}); | ||
} | ||
}; | ||
module.exports = customFunctions; | ||
module.exports = customFunctions; | ||
{ | ||
"name": "check-eos-watchdoggiee", | ||
"description": "CLI for watchdoggiee contract", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"main": "index.js", | ||
@@ -10,4 +10,4 @@ "author": { | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:orange1337/eos-nagios-plugins" | ||
"type": "git", | ||
"url": "git@github.com:orange1337/eos-nagios-plugins" | ||
}, | ||
@@ -28,5 +28,6 @@ "licenses": [ | ||
"colors": "^1.3.2", | ||
"commander": "^2.19.0" | ||
"commander": "^2.19.0", | ||
"eosjs": "^16.0.9" | ||
}, | ||
"keywords": [] | ||
} |
@@ -1,2 +0,2 @@ | ||
# Nagios js plugins for EOS blockchain | ||
# Check watchdoggiee | ||
@@ -13,9 +13,7 @@ ## Installation | ||
Check watchdoggiee: | ||
``` | ||
watchdoggiee --url http://api.eostribe.io | ||
BLOCKTIME OK - 0.440752s difference|time_diff=0.440752 | ||
``` | ||
[Mainnet] watchdoggiee -p [private key] -a [account] -k 111 -t 1.5 | ||
[Jungle] watchdoggiee -u http://jungle.cryptolions.io:18888 -p [private key] -a [account] -c 038f4b0fc8ff18a4f0842a8f0564611f6e96e8535901dd45e43ac8691a1c4dca -k 111 -t 1.5 | ||
REQTIME OK - 0.440752s difference|time_diff=0.440752 | ||
``` | ||
@@ -25,12 +23,18 @@ | ||
``` | ||
var nagios = require("eos-nagios-js"); | ||
var watchdoggiee = require("check-eos-watchdoggiee"); | ||
// example for check_nodeos_block_time function | ||
nagios.check_nodeos_block_time({ | ||
url: "http://api.eostribe.io", | ||
warn: 2, // in sec, | ||
crit: 10, // in sec, | ||
}, (err, result) => { | ||
console.log(err, result); | ||
}); | ||
watchdoggiee.check_eos_watchdoggiee({ | ||
url: [url], | ||
chain: [chain], | ||
key: [key], | ||
keyProvider: [keyProvider], | ||
account: [account], | ||
time: [time] | ||
}, (err, result) => { | ||
if (err){ | ||
return console.error(err); | ||
} | ||
console.log(result); | ||
}); | ||
@@ -37,0 +41,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5814
119
44
3
+ Addedeosjs@^16.0.9
+ Addedbabel-runtime@6.26.0(transitive)
+ Addedbase-x@3.0.10(transitive)
+ Addedbigi@1.4.2(transitive)
+ Addedbinaryen@37.0.0(transitive)
+ Addedbn.js@4.12.1(transitive)
+ Addedbrowserify-aes@1.2.0(transitive)
+ Addedbs58@4.0.1(transitive)
+ Addedbuffer-xor@1.0.3(transitive)
+ Addedbytebuffer@5.0.1(transitive)
+ Addedcamel-case@3.0.0(transitive)
+ Addedcipher-base@1.0.6(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addedcreate-hash@1.2.0(transitive)
+ Addedcreate-hmac@1.1.7(transitive)
+ Addedecurve@1.0.6(transitive)
+ Addedencoding@0.1.13(transitive)
+ Addedeosjs@16.0.9(transitive)
+ Addedeosjs-api@7.0.4(transitive)
+ Addedeosjs-ecc@4.0.4(transitive)
+ Addedevp_bytestokey@1.0.3(transitive)
+ Addedfcbuffer@2.2.2(transitive)
+ Addedhash-base@3.1.0(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedieee-float@0.6.0(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedisomorphic-fetch@2.2.1(transitive)
+ Addedlong@3.2.0(transitive)
+ Addedlower-case@1.1.4(transitive)
+ Addedmd5.js@1.3.5(transitive)
+ Addedno-case@2.3.2(transitive)
+ Addednode-fetch@1.7.3(transitive)
+ Addedrandombytes@2.1.0(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedregenerator-runtime@0.11.1(transitive)
+ Addedripemd160@2.0.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsha.js@2.4.11(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedupper-case@1.1.3(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwhatwg-fetch@3.6.20(transitive)