Skip to content

Commit

Permalink
Lots of changes.
Browse files Browse the repository at this point in the history
This commit is for #3
  • Loading branch information
ThatOneNeji committed Jan 22, 2018
1 parent 2e50fd3 commit aee5ff5
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 30 deletions.
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/nbproject/private/
nbproject
node_modules
logs
/nbproject/
/logs/
/node_modules/
/package-lock.json

# Ignore coverage results
/coverage/
.coveralls.yml
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: node_js
node_js:
- "6.12.3"
- "8.9.4"
- "9.4.0"
env:
- TZ="Africa/Johannesburg"
after_success:
- npm run coverage
- npm run report-coverage
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# netstatsNodeCron
netstatsNodeCron manages the cron for netstats

[![Build Status](https://travis-ci.org/ThatOneNeji/netstatsNodeCron.svg?branch=master)](https://travis-ci.org/ThatOneNeji/netstatsNodeCron)

netstatsNodeCron manages the cron for netstats group of applications

## Overview
This node application is one of the 4 main applications within the "netstats" collection of applications. While running it sends command requests to an AMQP instance which in turn is processed by <strong>netstatsNodeSNMPPoller</strong>.
This node application is one of the five main applications within the "netstats" collection of applications. While running it sends command requests to an AMQP instance which in turn is processed by **netstatsNode<_protocol_>Poller**.

## Hierarchy of netstats applications
* netstatsNodeCron - This application
* netstatsNodeSNMPPoller - The poller application that actions the requests from netstatsNodeCron
* netstatsNodeCron - **This application**
* netstatsNodeSNMPPoller - The poller application that actions the requests from netstatsNodeCron for the SNMP protocol
* netstatsNodeSSHPoller - The poller application that actions the requests from netstatsNodeCron for the SSH protocol
* netstatsNodeSNMPProcessor - The processing application that actions returned data from netstatsNodeSNMPPoller
* netstatsNodeMySQLLoader - Primary MySQL loader

Expand All @@ -28,7 +32,7 @@ This node application is one of the 4 main applications within the "netstats" co

## Planned/In progress
* Update the summary service so it is easier to add an additional summary services.
* Add "type" to the services that are used to poll the nodes. (Thinking SNMP/SSH for future proofing)
* Add field to nodes.json to indicate which service use which intervals; 1min, 5min, 10min, 15min
* Send that interval value with the request message to the message queue
* Add "reload nodes.json" configuration service.
* In **netstatsDisplay** add a configuration page for the nodes, services and protocols.
* Add some sort of function to pull that data from the DB and save it as a JSON file.

File renamed without changes.
47 changes: 34 additions & 13 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var appConfig = require('./settings.json');
var appServices = require('./services.json');
var appInternalServices = require('./internalservices.json');
var appProtocol = require('./protocols.json');
var appNodes;
var log4js = require('log4js'), moment = require('moment'), logger = log4js.getLogger('netstatsNodeCron'), cron1 = require('node-cron'), cron5 = require('node-cron'), cron10 = require('node-cron'), cron15 = require('node-cron');
Expand Down Expand Up @@ -32,7 +32,11 @@ function getNodes(target_array, service) {
var node_size = target_array[n]['services'].length;
for (var a = 0; a < node_size; a++) {
if (target_array[n]['services'][a] === service) {
target_nodes.push(target_array[n]['ip_address']);
let targetInfo = {
address: target_array[n]['ip_address'],
protocols: target_array[n]['protocols']
};
target_nodes.push(targetInfo);
}
}
}
Expand Down Expand Up @@ -87,9 +91,23 @@ function publisher(queuename, msg) {
logger.error(alreadyClosed.stackAtStateChange);
}
});
}).catch(console.warn);
}).catch(logger.warn);
}


function getElementDataByName(parray, ename) {
for (var f = 0; f < parray.length; f++) {
if (parray[f]['type'] === ename) {
var procotolInfo = {
name: parray[f]['name'],
port: parray[f]['port']
};
}
}
return procotolInfo;
}


function getTargetsForServices(source_array) {
var source_size = source_array.length;
for (var t = 0; t < source_size; t++) {
Expand All @@ -100,12 +118,15 @@ function getTargetsForServices(source_array) {
var tn_size = tn.length;
if (tn_size > 0) {
for (var d = 0; d < tn_size; d++) {
let protocolData = getElementDataByName(tn[d].protocols, source_array[t]['protocol']);
let msg = {
stime: moment().unix(),
etime: moment(moment().add(source_array[t]['services'][s]['age'], 'seconds')).unix(),
rdate: moment().format("YYYY/MM/DD HH:mm:00"),
service: source_array[t]['services'][s],
target: tn[d]
service: source_array[t]['services'][s]['name'],
target: tn[d].address,
name: protocolData['name'],
port: protocolData['port']
};
logger.info('Queue: ' + appConfig.amqp.queuename + source_array[t]['protocol'] + ' Msg: ' + JSON.stringify(msg));
publisher(appConfig.amqp.queuename + source_array[t]['protocol'], msg);
Expand Down Expand Up @@ -133,15 +154,15 @@ function inArray(needle, haystack) {

function runSummary() {
interval = moment().format("mm");
if (inArray(interval, appServices.summary['intervals'])) {
if (inArray(interval, appInternalServices.summary['intervals'])) {
logger.debug('Running summaries service for interval: ' + interval);
var lengthT = appServices.summary.update_sql.length;
var lengthT = appInternalServices.summary.update_sql.length;
for (var i = 0; i < lengthT; i++) {
let newMsg = {
service: appServices.summary['name'] + '___' + appServices.summary.update_sql[i]['name'],
sql: appServices.summary.update_sql[i]
service: appInternalServices.summary['name'] + '___' + appInternalServices.summary.update_sql[i]['name'],
sql: appInternalServices.summary.update_sql[i]
};
publisher(appServices.summary['queuename'], newMsg);
publisher(appInternalServices.summary['queuename'], newMsg);
}
} else {
logger.debug('No summaries service for interval: ' + interval);
Expand All @@ -150,7 +171,7 @@ function runSummary() {

function runReloadNodes() {
interval = moment().format("mm");
if (inArray(interval, appServices.reloadnodes['intervals'])) {
if (inArray(interval, appInternalServices.reloadnodes['intervals'])) {
logger.debug('Running reload node service for interval: ' + interval);
initLoadNodes();
} else {
Expand All @@ -159,9 +180,9 @@ function runReloadNodes() {
}

function runUpdates() {
if (appServices.summary['enabled'])
if (appInternalServices.summary['enabled'])
runSummary();
if (appServices.reloadnodes['enabled'])
if (appInternalServices.reloadnodes['enabled'])
runReloadNodes();
}

Expand Down
102 changes: 98 additions & 4 deletions nodes.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,102 @@
{
"nodes": [{
"name": "test_Device",
"name": "Device 1",
"enabled": false,
"ip_address": "192.168.100.1",
"services": ["ifmib", "host_resources_processor", "host_resources_storage"],
"protocols": [{
"type": "snmp",
"name": "public",
"port": 161
}, {
"type": "ssh",
"name": "ssh_user",
"port": 22
}]
}, {
"name": "Device 2",
"enabled": false,
"ip_address": "192.168.100.2",
"services": ["ifmib", "host_resources_processor", "host_resources_storage", "mikrotik_ap_client"],
"protocols": [{
"type": "snmp",
"name": "public",
"port": 161
}, {
"type": "ssh",
"name": "ssh_user",
"port": 22
}]
}, {
"name": "Device 3",
"enabled": false,
"ip_address": "192.168.100.3",
"services": ["ifmib", "host_resources_processor", "host_resources_storage"],
"protocols": [{
"type": "snmp",
"name": "public",
"port": 161
}, {
"type": "ssh",
"name": "ssh_user",
"port": 22
}]
}, {
"name": "Device 4",
"enabled": false,
"ip_address": "192.168.100.4",
"services": ["ifmib", "host_resources_processor", "host_resources_storage", "mikrotik_ap_client"],
"protocols": [{
"type": "snmp",
"name": "public",
"port": 161
}, {
"type": "ssh",
"name": "ssh_user",
"port": 22
}]
}, {
"name": "Device 5",
"enabled": true,
"ip_address": "192.168.1.1",
"services": ["ifmib", "host_resources_processor", "host_resources_storage", "mikrotik_ap_client"]
}]
"ip_address": "192.168.100.5",
"services": ["ifmib", "host_resources_processor", "host_resources_storage", "mikrotik_ap_client", "testing"],
"protocols": [{
"type": "snmp",
"name": "public",
"port": 161
}, {
"type": "ssh",
"name": "ssh_user",
"port": 22
}]
}, {
"name": "Device 6",
"enabled": true,
"ip_address": "192.168.0.253",
"services": ["testing"],
"protocols": [{
"type": "snmp",
"name": "public",
"port": 161
}, {
"type": "ssh",
"name": "ssh_user",
"port": 22
}]
}, {
"name": "Device 7",
"enabled": false,
"ip_address": "192.168.0.254",
"services": ["ifmib", "host_resources_processor", "host_resources_storage", "mikrotik_queuetree"],
"protocols": [{
"type": "snmp",
"name": "public",
"port": 161
}, {
"type": "ssh",
"name": "ssh_user",
"port": 22
}]
}
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"contributors": [],
"dependencies": {
"amqplib": "^0.5.2",
"log4js": "^2.4.1",
"log4js": "^2.5.2",
"moment": "^2.20.1",
"node-cron": "^1.2.1"
}
Expand Down
2 changes: 1 addition & 1 deletion protocols.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"enabled": true,
"intervals": [{
"value": "1",
"enabled": false,
"enabled": true,
"services": ["testing"],
"age": "30"
}, {
Expand Down

0 comments on commit aee5ff5

Please sign in to comment.