Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

check-eos-watchdoggiee

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

check-eos-watchdoggiee - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

19

lib/main.js

@@ -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);
}

113

lib/watchdoggiee.js

@@ -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 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc