Forum Discussion
How do I log information from a nodejs based LTM external monitor?
- Jul 06, 2020
If you don't mind running shell commands from your nodejs script (different ways to do this), then the most common command is logger -p <facility.level>... This article provides some examples and also recommends an alternative method, if you're willing to consider another trigger
https://support.f5.com/csp/article/K14397
If you don't mind running shell commands from your nodejs script (different ways to do this), then the most common command is logger -p <facility.level>... This article provides some examples and also recommends an alternative method, if you're willing to consider another trigger
https://support.f5.com/csp/article/K14397
- Algebraic_MirrorJul 15, 2020Cirrostratus
This ended up being what I had to do. I used the node.js "exec" command to run a shell command, which in this case was the Bash logger command. It worked well.
const { exec } = require('child_process'); exec('logger -p local0.notice "External Monitor ' + process.argv[1] + ' encountered an error: ' + e + '"', (error, stdout, stderr) => { //Output nothing. If there are errors with the logger command, we don't want to emit them, because if any text is emitted, the external monitor will be considered up. });
It should also be noted that "process.argv[1]" is just the name of the external monitor. It's passed in to external monitors as one of the arguments (that's just how external monitors work - they pass in some arguments to the script). So this is basically just putting the name of the external monitor that error'ed out into the log, combined with the actual log message, which is in the variable "e" (which comes from a try/catch block that isn't show here, but by convention when exceptions are thrown they pass back a variable called "e" to the catch block, so if you are printing an error inside a catch block, "e" is usually available to print out).
I am sure there has to be some better, native way to do this other than calling the logger command via exec. I'm sure there is probably either a built in facility in node, or some kind of module that would be nicer. So if anyone comes across this in the future and knows of a better way, please post it so we can all learn from it!
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com