Alerting

How to call Node.js instead of python or perl in Alert Script to fire results of the alert to an external system?

tdepuy
Path Finder

Hello,
I am writing an Alert Script to fire results of the Alert to an external system via REST API over HTTPS. Since python doesn't seem to be compiled with HTTPS support, I am looking at other options. It looks like there is a Node.js executable in /opt/splunk/bin which I tested:

boba@splunk:/opt/splunk/bin$
boba@splunk:/opt/splunk/bin$ pwd
/opt/splunk/bin
boba@splunk:/opt/splunk/bin$ ./node --version
v0.8.14
boba@splunk:/opt/splunk/bin$ ./node
> var https = require( 'https' )
undefined
>
undefined
> https
{ Server: { [Function: Server] super_: { [Function: Server] super_: [Object] } },
  createServer: [Function],
  globalAgent:
   { domain: null,
     _events: { free: [Function] },
     _maxListeners: 10,
     options: {},
     requests: {},
     sockets: {},
     maxSockets: 5,
     createConnection: [Function: createConnection] },
  Agent:
   { [Function: Agent]
     super_:
      { [Function: Agent]
        super_: [Function: EventEmitter],
        defaultMaxSockets: 5 } },
  request: [Function],
  get: [Function] }
>

However, when I try to call my "/opt/splunk/bin/scripts/test.js" script:


boba@splunk:/opt/splunk/bin/scripts$ cat test.js

!/opt/splunk/bin/node

"use strict"
var https = require( 'https' );
var fs = require( 'fs' );
var LOGFILE = "my.log"
fs.appendFile( LOGFILE, "Parms: " + process.argv + "\n" )

from the Alert, the splunkd.log prints this:

splunkd.log:10-16-2014 17:28:28.304 -0700 ERROR script - command="runshellscript", Cannot find script at /opt/splunk/bin/scripts/test.js

Despite this:


boba@splunk:/opt/splunk/bin/scripts$ file /opt/splunk/bin/scripts/test.js
/opt/splunk/bin/scripts/test.js: a /opt/splunk/bin/node script, ASCII text executable

0 Karma
1 Solution

tdepuy
Path Finder

Having a python wrapper script seems to work. This hard codes the path, but demonstrates the functionality.

#!/opt/splunk/bin/python

from subprocess import call
import sys

call( ["/opt/splunk/bin/node", "/opt/splunk/bin/scripts/test.js"] + sys.argv )

View solution in original post

0 Karma

jrodman
Splunk Employee
Splunk Employee

Alert script invocation supports #! scripts, so you can use an executable textfile that looks like #!/path/to/node on the first line.

Errrr, this should work anyway. I'll try it.

Yes, this error makes little sense.

In the current code, this is, in etc/apps/search/bin/runshellscript.py:

if not os.path.exists(script):
    results = splunk.Intersplunk.generateErrorResults('Cannot find script at ' +script)

So this message indeed means that path isn't available. Something else must be going on in the environment, or you may be using a version where this code is different.

0 Karma

tdepuy
Path Finder

Having a python wrapper script seems to work. This hard codes the path, but demonstrates the functionality.

#!/opt/splunk/bin/python

from subprocess import call
import sys

call( ["/opt/splunk/bin/node", "/opt/splunk/bin/scripts/test.js"] + sys.argv )
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...

Index This | How many sevens are there between 1 and 100?

August 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this ...