<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to call Node.js instead of python or perl in Alert Script to fire results of the alert to an external system? in Alerting</title>
    <link>https://community.splunk.com/t5/Alerting/How-to-call-Node-js-instead-of-python-or-perl-in-Alert-Script-to/m-p/169170#M2789</link>
    <description>&lt;P&gt;Having a python wrapper script seems to work. This hard codes the path, but demonstrates the functionality. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/opt/splunk/bin/python

from subprocess import call
import sys

call( ["/opt/splunk/bin/node", "/opt/splunk/bin/scripts/test.js"] + sys.argv )
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 23 Oct 2014 21:19:43 GMT</pubDate>
    <dc:creator>tdepuy</dc:creator>
    <dc:date>2014-10-23T21:19:43Z</dc:date>
    <item>
      <title>How to call Node.js instead of python or perl in Alert Script to fire results of the alert to an external system?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-call-Node-js-instead-of-python-or-perl-in-Alert-Script-to/m-p/169169#M2788</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;
  I am writing an Alert Script to fire results of the Alert to an external system via REST API over HTTPS. Since &lt;A href="http://answers.splunk.com/answers/172704/how-to-make-an-https-post-request-via-opsplunkbinp.html"&gt;python doesn't seem to be compiled with HTTPS support&lt;/A&gt;, I am looking at other options. It looks like there is a Node.js executable in /opt/splunk/bin which I tested:&lt;/P&gt;

&lt;PRE&gt;
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
&amp;gt; var https = require( 'https' )
undefined
&amp;gt;
undefined
&amp;gt; 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] }
&amp;gt;
&lt;/PRE&gt;

&lt;P&gt;However, when I try to call my "/opt/splunk/bin/scripts/test.js" script:&lt;BR /&gt;
&lt;PRE&gt;&lt;BR /&gt;
boba@splunk:/opt/splunk/bin/scripts$ cat test.js&lt;/PRE&gt;&lt;/P&gt;

&lt;H1&gt;!/opt/splunk/bin/node&lt;/H1&gt;

&lt;P&gt;"use strict"&lt;BR /&gt;
var https = require( 'https' );&lt;BR /&gt;
var fs    = require( 'fs' );&lt;BR /&gt;
var LOGFILE = "my.log"&lt;BR /&gt;
fs.appendFile( LOGFILE, "Parms: " + process.argv + "\n" )&lt;BR /&gt;
&lt;/P&gt;

&lt;P&gt;from the Alert, the &lt;CODE&gt;splunkd.log&lt;/CODE&gt; prints this:&lt;/P&gt;

&lt;PRE&gt;
splunkd.log:10-16-2014 17:28:28.304 -0700 ERROR script - command="runshellscript", Cannot find script at /opt/splunk/bin/scripts/test.js
&lt;/PRE&gt;

&lt;P&gt;Despite this:&lt;BR /&gt;
&lt;PRE&gt;&lt;BR /&gt;
boba@splunk:/opt/splunk/bin/scripts$ file /opt/splunk/bin/scripts/test.js&lt;BR /&gt;
/opt/splunk/bin/scripts/test.js: a /opt/splunk/bin/node script, ASCII text executable&lt;BR /&gt;
&lt;/PRE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Oct 2014 01:01:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-call-Node-js-instead-of-python-or-perl-in-Alert-Script-to/m-p/169169#M2788</guid>
      <dc:creator>tdepuy</dc:creator>
      <dc:date>2014-10-17T01:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to call Node.js instead of python or perl in Alert Script to fire results of the alert to an external system?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-call-Node-js-instead-of-python-or-perl-in-Alert-Script-to/m-p/169170#M2789</link>
      <description>&lt;P&gt;Having a python wrapper script seems to work. This hard codes the path, but demonstrates the functionality. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/opt/splunk/bin/python

from subprocess import call
import sys

call( ["/opt/splunk/bin/node", "/opt/splunk/bin/scripts/test.js"] + sys.argv )
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Oct 2014 21:19:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-call-Node-js-instead-of-python-or-perl-in-Alert-Script-to/m-p/169170#M2789</guid>
      <dc:creator>tdepuy</dc:creator>
      <dc:date>2014-10-23T21:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to call Node.js instead of python or perl in Alert Script to fire results of the alert to an external system?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-call-Node-js-instead-of-python-or-perl-in-Alert-Script-to/m-p/169171#M2790</link>
      <description>&lt;P&gt;Alert script invocation supports #! scripts, so you can use an executable textfile that looks like &lt;CODE&gt;#!/path/to/node&lt;/CODE&gt; on the first line.&lt;/P&gt;

&lt;P&gt;Errrr, this should work anyway.  I'll try it.&lt;/P&gt;

&lt;P&gt;Yes, this error makes little sense.&lt;/P&gt;

&lt;P&gt;In the current code, this is, in etc/apps/search/bin/runshellscript.py:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if not os.path.exists(script):
    results = splunk.Intersplunk.generateErrorResults('Cannot find script at ' +script)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Oct 2014 05:10:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-call-Node-js-instead-of-python-or-perl-in-Alert-Script-to/m-p/169171#M2790</guid>
      <dc:creator>jrodman</dc:creator>
      <dc:date>2014-10-24T05:10:38Z</dc:date>
    </item>
  </channel>
</rss>

