Hi,
Is there a way to register a webhook in order to get callbacks when devices are updated/registered or is the only way to periodically check for changes via api ?
Thanks
Hi,
Is there a way to register a webhook in order to get callbacks when devices are updated/registered or is the only way to periodically check for changes via api ?
Thanks
Use a preset that calls provision which calls an extension script.
Here is what I use to log bootstraps (another variation of this logs 1 BOOT as well):
//Send_Events provision script
let deviceId = null;
let serial = declare('DeviceID.SerialNumber', {value: 1}).value[0];
let productClass = declare('DeviceID.ProductClass', {value: 1}).value[0];
let model = declare('VirtualParameters.Model', {value: 1}).value[0];
let softwareVersion = declare('VirtualParameters.SoftwareVersion', {value: 1}).value[0];
let oui = declare('DeviceID.OUI', {value: 1}).value[0];
let events = args;
let did = declare('DeviceID.ID', {value: 1});
//Brand new devices won't have the Device.ID set yet
if (did.size) {
deviceId = did.value[0];
}
const params = {deviceId, serial, productClass, oui, model, softwareVersion, events};
ext('events', 'send', JSON.stringify(params));
You will need to edit your genieacs.env file and add an entry for API_URL (not GENIEACS_API_URL, just API_URL) that points to where ever you want the data posted to. Remember to restart the CWMP process after editing the .env file
//ext/events.js
const url = require('url');
const process = require('process');
const logger = require('../../lib/logger');
const API_URL = process.env.API_URL;
const https = require('./https').create();
function send(args, callback) {
let params = JSON.parse(args[0]);
const uri = API_URL + 'Event?serial=' + params.serial + '&productClass=' + params.productClass + '&oui=' + params.oui;
const logParams = { deviceId: params.deviceId, remoteAddress: 'events:send', events: params.events };
logger.info(Object.assign({ message: uri }, logParams, params));
let postData = JSON.stringify(params);
let options = url.parse(uri);
options.headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Content-Length': postData.length
};
options.method = 'POST';
let request = https.request(options, (response) => {
if (response.statusCode >= 400) {
logger.error(Object.assign({ message: 'Unexpected error sending event', statusCode: response.statusCode, statusMessage: response.statusMessage }, logParams));
return callback(new Error('Unexpected error sending event. Response Code: ' + response.statusCode + '. Status Message: ' + response.statusMessage));
}
let data = '';
response.on('data', function (d) {
data = data + d.toString();
});
response.on('end', function () {
return callback(null, data);
});
});
request.on('error', function (err) {
console.log('args');
console.log(arguments);
callback(err);
});
request.write(postData);
request.end();
}
exports.send = send;