Using node.js to display helpscout metrics - node.js

I am hoping someone can point me in the right direction.
I would like to use metrics-helpscout to bring back data that I can use for a dashboard. I am not having any luck. This is also my first time using node.js so I apologize in advance.
Here is what I have tried so far.
Following the instructions on github I used npm to install segmentio/metrics, metrics-helpscout and metrics-express.
I created a file called metrics.js and added this...
var Metrics = require('metrics');
var expressMetrics = require('metrics-express');
var helpscout = require('metrics-helpscout');
var express = require('metrics-express/node_modules/express');
var app = express();
console.log('start' );
var zzz = Metrics()
.every('1m', helpscout('myapi-key', ['my-mailbox-id']))
.on('helpscout active tickets', function (metric) {
console.log('helpscout update:' + metric.latest() );
});
var xxx = Metrics()
.every('1m', helpscout('myapi-key', ['my-mailbox-id']));
var date = new Date();
var val = 3;
var key = 'test';
var ddd = Metrics().set(key, val, date);
app.use('/', expressMetrics(xxx))
.listen(7002);
I then started the file by running node metrics.js
I opened a browser and hit the url and port and I just got back
[]
On the metrics express page example i used the var xxx. I thought I would get back a list of all the supported metrics. I then tested just using my var ddd and it did return my value. I am sure I am missing something or a lot.
Any help is appreciated.
Just in case it matters I am using ArchLinux.

Welp I figured it out. I generated a new API key and it worked.

Related

How can I extract the SAN's inside a .csr file in node.js (Serverless Framework)?

Using Serverless Framework with node.js, I need to read information inside a .csr file received via http POST. Using the node-forge module, and with the following code, I was able to extract the different information that composes the certificate signing request:
const forge = require('node-forge');
...
var csr = forge.pki.certificationRequestFromPem(cert);
console.log(csr.subject.attributes)
if(csr.subject.getField('CN'))
var CN = csr.subject.getField('CN').value
if(csr.subject.getField('SAN'))
var SAN = csr.subject.getField('SAN').value
if(csr.subject.getField('O'))
var O = csr.subject.getField('O').value
if(csr.subject.getField('OU'))
var OU = csr.subject.getField('OU').value
if(csr.subject.getField('C'))
var C = csr.subject.getField('C').value
if(csr.subject.getField('ST'))
var S = csr.subject.getField('ST').value
if(csr.subject.getField('L'))
var L = csr.subject.getField('L').value
if(csr.subject.getField('E'))
var E = csr.subject.getField('E').value
What I need right now is to also extract the SAN's of the CSR if they exist, problem is that after inspecting the x509.js file ("Javascript implementation of X.509 and related components (such as
Certification Signing Requests) of a Public Key Infrastructure") that comes within the module, I dot not think there is a way to extract the SAN's:
// short name OID mappings
var _shortNames = {};
_shortNames['CN'] = oids['commonName'];
_shortNames['commonName'] = 'CN';
_shortNames['C'] = oids['countryName'];
_shortNames['countryName'] = 'C';
_shortNames['L'] = oids['localityName'];
_shortNames['localityName'] = 'L';
_shortNames['ST'] = oids['stateOrProvinceName'];
_shortNames['stateOrProvinceName'] = 'ST';
_shortNames['O'] = oids['organizationName'];
_shortNames['organizationName'] = 'O';
_shortNames['OU'] = oids['organizationalUnitName'];
_shortNames['organizationalUnitName'] = 'OU';
_shortNames['E'] = oids['emailAddress'];
_shortNames['emailAddress'] = 'E';
Am I using a deprecated module or old version? Is there a way for me to achieve this and I'm simply using the incorrect stuff inside node-forge?
Please let me know if anyone had a similar problem or was able to overcome this issue. Regards
So, I was able to solve this with the following code:
var csr = forge.pki.certificationRequestFromPem(cert);
var altNames = csr.attributes.find(t=>t.name === 'extensionRequest').extensions.find(t=>t.name === 'subjectAltName').altNames;
I created a dummy certificate with SANs and Apparently node-forge extracts that information and places them inside extensionRequest -> subjectAltNames. I have these hardcoded since I'm assuming these attribute names will not change, but I can't be 100% sure about it.
Hope this helps someone who might have gone through this issue. Thank you.

How to use a proxy with the instagram-private-api for Node.js

Using a proxy with instagram-private-api.
Hi all, I spent a decent amount of time trying to figure this out and there is probably a really simple answer but I was seriously confused. When creating a session needed for the Instagram nodeJS API (private) you need a proxyUrl. I was wondering how to do / configure this? Do you need to create your own proxy server that you host?
Here is my code so far.
var Upload = require('instagram-private-api').V1;
var Client = require('instagram-private-api').V1;
var device = new Client.Device('test');
var storage = new Client.CookieFileStorage(__dirname +
'/cookies/test.json');
var photo = require('instagram-private-api').V1;
var username = 'testusername'
var password = 'testpassword'
var proxyUrl = '???'
Client.Session.create(device, storage, username, password, proxyUrl)
var Upload = require('./node_modules/instagram-private-api/client/v1/Upload.js')
var session = new Client.Session(device, storage, 'test', 'test')
Upload.photo(session, 'aaaa.jpg')
.then(function(upload) {
console.log(upload.params.uploadId);
return Media.configurePhoto(session, upload.params.uploadId, 'henlo world');
})
.then(function(medium) {
console.log(medium.params)
})
I know my code is probably seriously flawed as well, criticism is appreciated! Here's the link to the GitHub of the Node.JS wrapper mentioned. Here.
e
Hi there Benjamin,
I'm really looking forward to helping you.
As already stated, this library won't be upkept and maintained and could become irrelevant in updates to the official API.
I believe one has to set up a proxy url on their phone.

ol3 / OpenLayers 3: How to use readNetworkLinks method for ol.format.KML()?

I am looking for some guidance on how to implement the readNetworkLinks method of ol.format.KML() in OL3.
var kmlURL = 'kml/NLExample/TestLinkNL.kml'
var kmlFormat = new ol.format.KML()
var vectorSource = new ol.source.Vector({
url: kmlURL,
format: kmlFormat
});
I use the above code to create a KML layer with no problems, but I need to also display other KML that are referenced via network links in the top-level KML. I'm not quite sure the syntax for using the readNetworkLinks() method.
readNetworkLinks takes a KML document as String, so you would have to load your file manually and then parse the network links:
var source = new ol.source.Vector();
var url = 'kml/NLExample/TestLinkNL.kml';
$.ajax(url).then(function(response) {
var kmlFormat = new ol.format.KML();
var features = kmlFormat.readFeatures(response);
source.addFeatures(features);
// read the network links
var links = kmlFormat.readNetworkLinks(response);
// ...
});

Determine whether the domino server is running or not ( session.getDatabase(..) takes too long when the corresponding server is down )

I have approximately 4-5 users on different servers and need to find free time based on the calendar entries. Till last night the functionality was working great, however, today we just figured out a small issue/bug. One of the server machine was offline today and SSJS took around a minute (60 seconds) to figure that out.
Is there any such option to verify whether the server is running? I am asking this since session.getDatabase takes a long time to provide any results in such case.
Just for reference, below is my code to verify users mail database accessibility. It works perfectly fine when all servers are up, however, the waiting time is too long when any server is down.
// Set up the names
var names = new java.util.Vector();
var inaccessible_calendars = new java.util.Vector();
var infoDoc:NotesDocument= database.getDocumentByUNID(context.getUrlParameter('refId'));
var members:java.util.Vector = infoDoc.getItemValue("members");
names = infoDoc.getItemValue("members");
//var members:java.util.Vector = infoDoc.getItemValue("members");
var membersIterator = members.iterator();
var maildb ="";
while(membersIterator.hasNext()){
var val = membersIterator.next();
var nab:NotesDatabase=session.getDatabase(database.getServer(),"names.nsf")
var nview:NotesView=nab.getView("($NamesFieldLookup)")
var doc:NotesDocument=nview.getDocumentByKey(val,true)
if(doc){
var email = doc.getItemValueString("MailFile")
var emailServer = doc.getItemValueString("MailServer")
doc.recycle()
nview.recycle()
nab.recycle()
maildb=#LowerCase(emailServer)+'!!'+#LowerCase(email)+ '.nsf'
var emailServerCN = #Name("[CN]",#LowerCase(emailServer));
var emailDBName = #LowerCase(email)+ '.nsf';
emailDBName = emailDBName.replace("\\","\/");
try{
if(session.getDatabase(emailServerCN.toString(),emailDBName.toString())==null){
names.remove(val);
inaccessible_calendars.add(val);
}else{
var emailDB:NotesDatabase = session.getDatabase(emailServerCN.toString(),emailDBName.toString());
if(!(emailDB.getCurrentAccessLevel()>0)){
names.remove(val);
inaccessible_calendars.add(val);
}
}
}catch(err){
names.remove(val);
inaccessible_calendars.add(val);
}
} else {
nview.recycle()
nab.recycle()
maildb= ""
}
}
if(!inaccessible_calendars.isEmpty())
return "Following calendars are not accessible"+inaccessible_calendars.toString()+"*";
Any help would be really appreciated.
Are these database in a cluster? Can they be? If so then when you open it there an "OpenWithFailOver" method I forget the exact syntax. But if the database in unavailable it should open another in the cluster.

Apache Thrift with nodejs example

I am trying to use Apache Thrift for passing messages between applications implemented in different languages. It is not necessarily used as RPC, but more for serializing/deserializing messages.
One application is in node.js. I am trying to figure out how Apache thrift works with node.js, but I can't find too much documentation and examples, except for one tiny one regarding Cassandra at:
https://github.com/apache/thrift/tree/trunk/lib/nodejs
Again, I don't need any procedures declared in the .thrift file, I only need to serialize a simple data structure like:
struct Notification {
1: string subject,
2: string message
}
Can anyone help me with an example?
I finally found the answer to this question, after wasting a lot of time just by looking at the library for nodejs.
//SERIALIZATION:
var buffer = new Buffer(notification);
var transport = new thrift.TFramedTransport(buffer);
var binaryProt = new thrift.TBinaryProtocol(transport);
notification.write(binaryProt);
At this point, the byte array can be found in the transport.outBuffers field:
var byteArray = transport.outBuffers;
For deserialization:
var tTransport = new thrift.TFramedTransport(byteArray);
var tProtocol = new thrift.TBinaryProtocol(tTransport);
var receivedNotif = new notification_type.Notification();
receivedNotif.read(tProtocol);
Also the following lines need to be added to the index.js file from the nodejs library for thrift:
exports.TFramedTransport = require('./transport').TFramedTransport;
exports.TBufferedTransport = require('./transport').TBufferedTransport;
exports.TBinaryProtocol = require('./protocol').TBinaryProtocol;
Plus there is also at least one bug in the nodejs library.
The above answer is wrong, because it tries to use outBuffers directly, which is an array of buffers. Here is a working example of using thrift with nodejs:
var util = require('util');
var thrift = require('thrift');
var Notification = require('./gen-nodejs/notification_types.js').Notification;
var TFramedTransport = require('thrift/lib/thrift/transport').TFramedTransport;
var TBufferedTransport = require('thrift/lib/thrift/transport').TBufferedTransport;
var TBinaryProtocol = require('thrift/lib/thrift/protocol').TBinaryProtocol;
var transport = new TFramedTransport(null, function(byteArray) {
// Flush puts a 4-byte header, which needs to be parsed/sliced.
byteArray = byteArray.slice(4);
// DESERIALIZATION:
var tTransport = new TFramedTransport(byteArray);
var tProtocol = new TBinaryProtocol(tTransport);
var receivedNotification = new Notification();
receivedUser.read(tProtocol);
console.log(util.inspect(receivedNotification, false, null));
});
var binaryProt = new TBinaryProtocol(transport);
// SERIALIZATION:
var notification = new Notification({"subject":"AAAA"});
console.log(util.inspect(notification, false, null));
notification.write(binaryProt);
transport.flush();
DigitalGhost is right, the previous example is wrong.
IMHO the outBuffers is a private property to the transport class and should not be accessed.

Resources