Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
["host", "username", "password", "query", "keyColumn"].forEach((item) => {
if (this[item] === undefined) {
console.log(this.section, `- ERROR not loading since no ${item} specified in config file`);
return;
}
});
if (this.periodic) {
this.cacheTimeout = -1; // Don't cache
this[this.api.funcName(this.type)] = this.sendResultPeriodic;
setInterval(this.periodicRefresh.bind(this), 1000 * this.periodic);
} else {
this[this.api.funcName(this.type)] = this.sendResult;
}
this.service = new splunkjs.Service({username: this.username, password: this.password, host: this.host, port: this.port, version: this.version});
this.service.login((err, success) => {
if (err) {
console.log("ERROR - Couldn't login to splunk - ", err);
return;
}
if (this.periodic) {
this.periodicRefresh();
}
console.log("Login was successful: " + success);
});
api.addSource(section, this);
this.sourceFields = [this.esResultField];
exports.getOrStoreSecrets = function (name, singleInput, done) {
// make a copy of singleInput
var mySingleInput = JSON.parse(JSON.stringify(singleInput));
var inputDefinition = ModularInput._inputDefinition;
var session_key = inputDefinition.metadata.session_key;
var service = new splunkjs.Service({ sessionKey: session_key });
var storagePasswords = service.storagePasswords({ 'app': 'TA-Azure_Monitor' });
var propsAppId = {};
var propsAppKey = {};
if (~name.indexOf('azure_activity_log:')) {
propsAppId.name = 'AzureMonitorActivityLogAppID';
propsAppKey.name = 'AzureMonitorActivityLogAppKey';
} else {
propsAppId.name = 'AzureMonitorDiagnosticLogsAppID';
propsAppKey.name = 'AzureMonitorDiagnosticLogsAppKey';
}
propsAppId.password = singleInput.SPNApplicationId;
propsAppKey.password = singleInput.SPNApplicationKey;
if (_.isUndefined(singleInput.SPNApplicationId) && _.isUndefined(singleInput.SPNApplicationKey)) {
done(null, singleInput);
}
var parsed = url.parse(host);
if (parsed.protocol == null) {
parsed.protocol = nconf.get('scheme') + ':';
}
if (parsed.port == null) {
parsed.port = nconf.get('port');
}
var scheme = parsed.protocol.substring(0, parsed.protocol.length - 1);
var service = new splunk.Service({
host:parsed.hostname,
scheme:scheme,
username:user,
password:pwd,
port:parsed.port
});
return service;
}
var config = require('./../config');
if(config.splunk && config.splunk.indexObj){
var splunk = require('splunk-sdk');
var splunkService = new splunk.Service({
host: config.splunk.host,
port: config.splunk.port,
scheme: config.splunk.protocol,
username: config.splunk.user,
password: config.splunk.password
});
var myindexes = splunkService.indexes();
myindexes.fetch(function(err, myindexes) {
if(myindexes){
config.splunk.indexObj = myindexes.item(config.splunk.index);
}
});
module.exports = splunkService;
}