Skip to content

Instantly share code, notes, and snippets.

@tomasinouk
Last active November 18, 2015 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomasinouk/f1b42cd57969d4468c5e to your computer and use it in GitHub Desktop.
Save tomasinouk/f1b42cd57969d4468c5e to your computer and use it in GitHub Desktop.
Westermo SNMP SHDSL

Speed of SHDSL(1):

IF-MIB::ifSpeed.4096 = Gauge32: 15288000

  • OID: snmptranslate -On IF-MIB::ifSpeed.4096 -> .1.3.6.1.2.1.2.2.1.5.4096

SHDSL IN:

IF-MIB::ifInOctets.4096 = Counter32: 10923350

  • OID snmptranslate -On IF-MIB::ifInOctets.4096 -> .1.3.6.1.2.1.2.2.1.10.4096

SHDSL OUT:

  • IF-MIB::ifInOctets.4098 = Counter32: 13242959
  • IF-MIB::ifOutOctets.4096 = Counter32: 13084934

OID: snmptranslate -On IF-MIB::ifOutOctets.4096 -> .1.3.6.1.2.1.2.2.1.16.4096

Temperature:

SNMPv2-SMI::mib-2.99.1.1.1.4.1000 = INTEGER: 43

OID: snmptranslate -On SNMPv2-SMI::mib-2.99.1.1.1.4.1000 -> .1.3.6.1.2.1.99.1.1.1.4.1000

SNR:

SNMPv2-SMI::transmission.48.1.5.1.2.4096.0.0.1 = INTEGER: 12

OID: snmptranslate -On SNMPv2-SMI::transmission.48.1.5.1.2.4096.0.0.1 -> .1.3.6.1.2.1.10.48.1.5.1.2.4096.0.0.1

Dirty version

#! /usr/bin/env node

// var snmp = require('./lib/index.js');
// needs to be download as NPM have old version without client.js
var snmp = require('./node-snmpjs-master/lib/index.js');
var bunyan = require('bunyan');
var util = require('util');
var fs = require("fs");

var bitrate = require('bitrate')


console.info(bitrate(15288000, 1, 'KBps'));

var jsonfile = require('jsonfile')
 
var file = './data.json'
// var obj = {name: 'JP'}


var device_obj = {
	ip: "10.1.1.3",
	community: "public",
	oid: {
	TxTotal: '.1.3.6.1.2.1.2.2.1.10.4096', // SNMPv2-SMI::mib-2.16.1.1.1.4.2
	RxTotal: '.1.3.6.1.2.1.2.2.1.16.4096',	// SNMPv2-SMI::mib-2.16.1.1.1.4.0
	Temperature: '.1.3.6.1.2.1.99.1.1.1.4.1000',
	Speed: '.1.3.6.1.2.1.2.2.1.5.4096',
	SNR: '.1.3.6.1.2.1.10.48.1.5.1.2.4096.0.0.1'
	}
};

// var snmp_data = {
// 	TxTotal: 0,
// 	RxTotal: 0,
// 	Temperature: 0
// };
var snmp_data = {};

var client = snmp.createClient({
	log: new bunyan({ name: 'snmpget', level: 'info' })
	// console.info("createClient");
});

function print_get_response(snmpmsg)
{
	var value;
	snmpmsg.pdu.varbinds.forEach(function (varbind) {
		console.log(varbind.oid + ' = ' + varbind.data.value);
		value = varbind.data.value;
	});
	console.info("value: " + value);
	return value;
}

// var ip = process.argv[2];
// var community = process.argv[3];
// var oid = process.argv[4];

var ip = "192.168.88.104";
var community = "public";
var oid = '.1.3.6.1.2.1.31.1.1.1.6.7'; // total IN on interface
var oid2 = '.1.3.6.1.2.1.31.1.1.1.10.7'; // total OUT on interface


console.info(device_obj);
// console.info(JSON.stringify(snmp_data));
console.info(device_obj.oid.TxTotal);

var one = setTimeout(function() {
client.get(device_obj.ip, device_obj.community, 1, device_obj.oid.TxTotal, function (snmpmsg) {
	var o = parseInt(print_get_response(snmpmsg));
	console.info("objects o: " + o);
	snmp_data.TxTotal = o;
	// console.log(print_get_response(snmpmsg));
	// client.unref();
	client.close();

});
},1000);

var two = setTimeout(function() {

client.get(device_obj.ip, device_obj.community, 1, device_obj.oid.RxTotal, function (snmpmsg) {
	
	snmp_data.RxTotal = parseInt(print_get_response(snmpmsg));
	// client.unref();
	client.close();

});
},2000);

var five = setTimeout(function() {

client.get(device_obj.ip, device_obj.community, 1, device_obj.oid.SNR, function (snmpmsg) {
	
	snmp_data.SNR = parseInt(print_get_response(snmpmsg));
	// client.unref();
	client.close();

});
},2500);

var three = setTimeout(function() {

client.get(device_obj.ip, device_obj.community, 1, device_obj.oid.Temperature, function (snmpmsg) {
	var temp = print_get_response(snmpmsg);
	snmp_data.TemperatureC = temp;
	//snmp_data.Temperature =  print_get_response(snmpmsg);
	// client.unref();
	client.close();

});
},3000);


var four = setTimeout(function() {

client.get(device_obj.ip, device_obj.community, 1, device_obj.oid.Speed, function (snmpmsg) {
	snmp_data.SpeedKBps =  bitrate(print_get_response(snmpmsg),1, 'KBps');
	// console.info(bitrate(15288000, 1, 'KBps'));
	// client.unref();
	client.close();

});
},3500);

setTimeout(function() {
	console.info(snmp_data);
	jsonfile.writeFile(file, snmp_data, {spaces: 2}, function(err) {
  console.error(err)
})
}, 4000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment