@interlink-sa/strings-api

2.2.3 • Public • Published

strings-api v2.0

The API allows you to use the Strings Services

How to use

Devices Functions

import {createDevices, getDevice, listDevices, deleteDevice} from './api';

let devices = [
    {
        "device_type" : "cmts",
        "short_name" : "DEV001",
        "name" : "Device Name",
        "ip" : "127.0.0.1",
        "password" : "snmp-community",
        "region" : "Santa Fe",
        "city" : "Rosario",
        "location" : {
            "latitude" : -32.9580172,
            "longitude" : -60.6326825
        },
        "extra_data" : {
            "mark" : "CASA Systems",
            "model" : "C40G",
            "docsis" : 3
        },
        string: null
    }
];

/**
 *  Create devices
 * 
 * @param {array} devices - Array with devices objects
 */
createDevices(devices)
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 * Get a device
 * 
 * @param {string} deviceId
 */
getDevice("5c9e534dbf29163a949eaa5a")
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 * Search for devices
 * 
 * @param {object} filter -> Object with filter
 * @param {number} offset -> Start from
 * @param {number} limit -> Total of registers
 * @param {string} sort -> Field to sort by (`fieldname` for asc and `-fieldname` for desc)
 * @param {boolean} aggregate -> Aggregate the String and Parent Device if any
 */
listDevices({city: "Rosario"}, 0, 20, '+ip')
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 *  Search for devices executing complex filters
 * 
 * @param {object} filter -> Object with filter
 * @param {number} offset -> Start from
 * @param {number} limit -> Total of registers
 * @param {string} sort -> Field to sort by (`fieldname` for asc and `-fieldname` for desc)
 */
let filter = {device_type: 'cmts', $or: [ { 'stats_powers.rx': {$gte: 20} }, { 'stats_powers.rx': {$lte: 15} } ]};
listDevices(filter, 0, 20)
    .then((result) => {console.log(result)})
    .catch((error) => {console.log(error)});

/**
 * Delete a device
 * 
 * @param {string} deviceId
 */
deleteDevice("5c9e534dbf29163a949eaa5a")
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

Metrics Functions

import {saveMetrics, getMetrics, deleteMetrics} from './api';

/* {d:device, t:tags, v: values({time: {tag1:value, tag2:value}})} */

const metrics = [
    {
        "d" : "cmts:EX01",
        "t" : ["aux_xx","aux_yy"],
        "v" : [
            {"1548268817" : {"aux_xx" : 254102, "aux_yy" : 125410}},
            {"1548269117" : {"aux_xx" : 286185, "aux_yy" : 135200}}
        ]
    },{
        "d" : "cmts:EX01",
        "t" : ["aux_yy","aux_xx"],
        "v" : [
            {"1548272817" : {"aux_xx" : 254102, "aux_yy" : 125410}},
            {"1548275117" : {"aux_xx" : 386185, "aux_yy" : 155200}},
            {"1548278117" : {"aux_xx" : 296185, "aux_yy" : 165200}}
        ]
    },
    "cmts:EX01 aux_xx:254103,aux_yy:125025 1548308117",
    "cmts:EX01 aux_xx:true,aux_yy:false 1548308118",
    "cmts:EX01 aux_xx:null,aux_yy:null 1548308119",
    "cmts:EX01 aux_xx:000.45,aux_yy:125.52 1548308120",
    "cmts:EX01 aux_xx:false,aux_yy:125.52 1548308130",
    "cmts:EX01 aux_xx:25 1548308125"
];

/**
 * Save metrics
 * 
 * @param {array} metrics - Array with metrics objects
 */
saveMetrics(metrics)
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});


/**
 * Get metrics
 * 
 * @param {array} series - Array with series objects
 */
let series = [{"d" : "cmts:EX01", "t" : ["aux_xx","aux_yy"], "from" : 1548268817, "to" : 1548308240000}];
getMetrics(series)
    .then((result) => {
        let series = result.series;
        console.log(series['cmts:EX01']['aux_xx']);
        console.log(result);
    })
    .catch((error) => {console.log(error); process.exit(0);})

/**
 * Delete metrics
 * 
 * @param {array} metrics - Array with metrics objects
 */
deleteMetrics(series)
    .then((result) => {console.log(result); process.exit(0);})
    .catch((error) => {console.log(error); process.exit(0);})

Strings Functions

import {devicesToString, listStrings, createString, getString, getDevicesWithoutString, deleteString} from './api';

let variable = Date.now();
let stringNname = `New string ${variable}`;

/**
 * Create a string
 * 
 * @param {array} string - Object of string
 */
createString({name: stringNname})
    .then((result) => {console.log(result)})
    .catch((error) => {console.log(error)});

/**
 * Update a string
 * 
 * @param {string} stringId
 * @param {Object} string - Object of string
 */
updateString("5c9e54e3719ace3c59f0fec9", {name: stringNname})
    .then((result) => {console.log(result)})
    .catch((error) => {console.log(error)});


/**
 * Get a string
 * 
 * @param {string} stringId
 */
getString("5c9e54e3719ace3c59f0fec9")
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 * Search for strings
 * 
 * @param {object} filter -> Object with filter
 * @param {number} offset -> Start from
 * @param {number} limit -> Total of registers
 * @param {string} sort -> Field to sort by (`fieldname` for asc and `-fieldname` for desc)
 */
listStrings({name: stringName}, 0, 20)
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 * Get Status of a string
 * 
 * @param {array} stringId
 */
getStatusOfString(["5c9e54e3719ace3c59f0fec9"])
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 * Get Status of a device
 * 
 * @param {array} deviceId
 */
getStatusOfDevice(["5c9e534dbf29163a949eaa5a"])
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 * Get Strings attached to a device or a parent device
 * 
 * @param {array} deviceId
 * @param {object} filter -> Object with filter
 * @param {number} offset -> Start from
 * @param {number} limit -> Total of registers
 * @param {string} sort -> Field to sort by (`fieldname` for asc and `-fieldname` for desc)
 */
getStringsOfDevice(["5c9e534dbf29163a949eaa5a"])
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 * Delete a string
 * 
 * @param {string} stringId
 */
deleteString("5c9e54e3719ace3c59f0fec9")
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 * Attach devices to a string
 * 
 * @param {string} stringId
 * @param {array} devices - Array with devicesIds
 */
attachDevicesToString('5c9e54e3719ace3c59f0fec9',['5c9e534dbf29163a949eaa5a','5c9e534dbf29163a949eaa5b'])
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 * Detach devices of string
 * 
 * @param {string} stringId
 * @param {array} devices - Array with devicesIds
 */
detachDevicesOfString('5c9e54e3719ace3c59f0fec9',['5c9e534dbf29163a949eaa5a','5c9e534dbf29163a949eaa5b'])
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

/**
 * Search for devices without a string configured
 * 
 * @param {object} filter -> Object with filter
 * @param {number} offset -> Start from
 * @param {number} limit -> Total of registers
 * @param {string} sort -> Field to sort by (`fieldname` for asc and `-fieldname` for desc)
 */
getDevicesWithoutString({}, 0, 20)
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

Anomalies Functions

/**
 * Search types of anomalies for cablemodems
 * 
 * @param {object} filter -> Object with filter
 * @param {number} offset -> Start from
 * @param {number} limit -> Total of registers
 * @param {string} sort -> Field to sort by (`fieldname` for asc and `-fieldname` for desc)
 */
getAnomalies({device_type:'cm'}, 0, 20)
    .then((result) => {console.log(result);})
    .catch((error) => {console.log(error);});

Readme

Keywords

none

Package Sidebar

Install

npm i @interlink-sa/strings-api

Weekly Downloads

1

Version

2.2.3

License

ISC

Unpacked Size

52.2 kB

Total Files

13

Last publish

Collaborators

  • mmalisani
  • marksonmarcolino