Import Splunk Add-On for Unix and Linux version 9.2.0
This commit is contained in:
commit
92ac2630a1
77 changed files with 11487 additions and 0 deletions
BIN
appserver/static/appIcon.png
Normal file
BIN
appserver/static/appIcon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
19
appserver/static/components/js_sdk_extensions/common.js
Normal file
19
appserver/static/components/js_sdk_extensions/common.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 Splunk, Inc. <sales@splunk.com>
|
||||
* SPDX-License-Identifier: LicenseRef-Splunk-8-2021
|
||||
*
|
||||
*/
|
||||
|
||||
define([], function () {
|
||||
var utils_namespaceFromProperties = function (props) {
|
||||
return {
|
||||
owner: props.acl.owner,
|
||||
app: props.acl.app,
|
||||
sharing: props.acl.sharing
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
utils_namespaceFromProperties: utils_namespaceFromProperties
|
||||
}
|
||||
})
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 Splunk, Inc. <sales@splunk.com>
|
||||
* SPDX-License-Identifier: LicenseRef-Splunk-8-2021
|
||||
*
|
||||
*/
|
||||
|
||||
define([
|
||||
'splunkjs/ready!', // for splunkjs global
|
||||
'./common'
|
||||
], function (mvc, sdkx_common) {
|
||||
var root = {
|
||||
Entity: splunkjs.Service.Entity,
|
||||
Collection: splunkjs.Service.Collection
|
||||
}
|
||||
|
||||
var utils_namespaceFromProperties = sdkx_common.utils_namespaceFromProperties
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// JS SDK Extension: Monitor Inputs
|
||||
|
||||
var Paths = {
|
||||
monitorInputs: 'data/inputs/monitor'
|
||||
}
|
||||
|
||||
root.MonitorInput = root.Entity.extend({
|
||||
path: function () {
|
||||
return Paths.monitorInputs + '/' + encodeURIComponent(this.name)
|
||||
},
|
||||
|
||||
init: function (service, name, namespace) {
|
||||
this.name = name
|
||||
this._super(service, this.path(), namespace)
|
||||
}
|
||||
})
|
||||
|
||||
root.MonitorInputs = root.Collection.extend({
|
||||
path: function () {
|
||||
return Paths.monitorInputs
|
||||
},
|
||||
|
||||
instantiateEntity: function (props) {
|
||||
var entityNamespace = utils_namespaceFromProperties(props)
|
||||
return new root.MonitorInput(this.service, props.name, entityNamespace)
|
||||
},
|
||||
|
||||
init: function (service, namespace) {
|
||||
this._super(service, this.path(), namespace)
|
||||
}
|
||||
})
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
return root
|
||||
})
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 Splunk, Inc. <sales@splunk.com>
|
||||
* SPDX-License-Identifier: LicenseRef-Splunk-8-2021
|
||||
*
|
||||
*/
|
||||
|
||||
define([
|
||||
'splunkjs/ready!', // for splunkjs global
|
||||
'./common'
|
||||
], function (mvc, sdkx_common) {
|
||||
var root = {
|
||||
Entity: splunkjs.Service.Entity,
|
||||
Collection: splunkjs.Service.Collection
|
||||
}
|
||||
|
||||
var utils_namespaceFromProperties = sdkx_common.utils_namespaceFromProperties
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// JS SDK Extension: Scripted Inputs
|
||||
|
||||
var Paths = {
|
||||
scriptedInputs: 'data/inputs/script'
|
||||
}
|
||||
|
||||
root.ScriptedInput = root.Entity.extend({
|
||||
path: function () {
|
||||
// Approximate path - accepts reads only
|
||||
// ex: data/inputs/script/%2FApplications%2Fsplunk_622light_unix%2Fetc%2Fapps%2FSplunk_TA_nix%2Fbin%2Fcpu.sh
|
||||
return Paths.monitorInputs + '/' + encodeURIComponent(this.name)
|
||||
},
|
||||
|
||||
init: function (service, name, namespace) {
|
||||
this.name = name
|
||||
this._super(service, this.path(), namespace)
|
||||
},
|
||||
|
||||
_load: function (properties) {
|
||||
this._super(properties)
|
||||
|
||||
// HACK: Patch path to be canonical version to enable updates
|
||||
//
|
||||
// Canonical path - accepts reads and updates
|
||||
// ex: data/inputs/script/.%252Fbin%252Fcpu.sh
|
||||
if (this.state().id) {
|
||||
this.qualifiedPath = this.state().id.match(/\/servicesNS\/.*$/)[0]
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
root.ScriptedInputs = root.Collection.extend({
|
||||
path: function () {
|
||||
return Paths.scriptedInputs
|
||||
},
|
||||
|
||||
instantiateEntity: function (props) {
|
||||
var entityNamespace = utils_namespaceFromProperties(props)
|
||||
return new root.ScriptedInput(this.service, props.name, entityNamespace)
|
||||
},
|
||||
|
||||
init: function (service, namespace) {
|
||||
this._super(service, this.path(), namespace)
|
||||
}
|
||||
})
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
return root
|
||||
})
|
64
appserver/static/setup.css
Normal file
64
appserver/static/setup.css
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
SPDX-FileCopyrightText: 2021 Splunk, Inc. <sales@splunk.com>
|
||||
SPDX-License-Identifier: LicenseRef-Splunk-8-2021
|
||||
|
||||
*/
|
||||
|
||||
/* Hide Simple XML dashboard controls: Edit, Export PDF, Print */
|
||||
.dashboard-view-controls {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
#overview {
|
||||
max-width: 500px;
|
||||
text-align: justify;
|
||||
}
|
||||
|
||||
.error-box {
|
||||
display: none;
|
||||
color: white;
|
||||
background-color: #d85d3c; /* red */
|
||||
padding: 0.5em;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.input-table th {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.input-table th,
|
||||
.input-table td {
|
||||
padding: 0 10px 0 10px;
|
||||
}
|
||||
|
||||
.input-table input[type='radio'] {
|
||||
margin: 4px; /* override with symmetric margins */
|
||||
}
|
||||
|
||||
.input-table .interval-field {
|
||||
width: 4em; /* narrower than default */
|
||||
text-align: right; /* make the numbers line up */
|
||||
padding: 2px; /* reduce from default of 4 */
|
||||
height: 30px; /* reduce height */
|
||||
margin-top: 12.5px; /* inline with index dropdown */
|
||||
}
|
||||
|
||||
#btn-bar {
|
||||
margin-top: 1em; /* separate from table */
|
||||
}
|
||||
|
||||
#btn-bar #save-btn {
|
||||
padding-left: 3em;
|
||||
padding-right: 3em; /* made it wider */
|
||||
}
|
||||
|
||||
#index-selection .splunk-dropdown {
|
||||
max-width: 50%; /* fix the width of dropdown */
|
||||
width: 300px; /* default width of dropdown */
|
||||
margin-left: 0; /* remove left margin for inlinement */
|
||||
height: 30px; /* reduce height */
|
||||
}
|
||||
|
||||
.table-header {
|
||||
width: 150px;
|
||||
}
|
314
appserver/static/setup.js
Normal file
314
appserver/static/setup.js
Normal file
|
@ -0,0 +1,314 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 Splunk, Inc. <sales@splunk.com>
|
||||
* SPDX-License-Identifier: LicenseRef-Splunk-8-2021
|
||||
*
|
||||
*/
|
||||
|
||||
require([
|
||||
'splunkjs/ready!',
|
||||
'splunkjs/mvc/simplexml/ready!',
|
||||
'underscore',
|
||||
'jquery',
|
||||
'../app/Splunk_TA_nix/components/js_sdk_extensions/scripted_inputs',
|
||||
'../app/Splunk_TA_nix/components/js_sdk_extensions/monitor_inputs'
|
||||
], function (mvc, ignored, _, $, sdkx_scripted_inputs, sdkx_monitor_inputs) {
|
||||
var ScriptedInputs = sdkx_scripted_inputs.ScriptedInputs
|
||||
var MonitorInputs = sdkx_monitor_inputs.MonitorInputs
|
||||
|
||||
var service = mvc.createService()
|
||||
var cleaned_data = {}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Prerequisite Checks
|
||||
|
||||
// Error if running on unrecognized unix
|
||||
//
|
||||
service.get('/services/SetupService', cleaned_data, function (err, response) {
|
||||
if (err) {
|
||||
console.error('Problem fetching data', err)
|
||||
} else if (response.status === 200) {
|
||||
var isRecognizedUnix = JSON.parse(response.data)
|
||||
if (!isRecognizedUnix) {
|
||||
$('#not-unix-error').show()
|
||||
$('#save-btn').addClass('disabled')
|
||||
}
|
||||
} else {
|
||||
console.error('Problem checking whether splunkweb is running on Unix.')
|
||||
}
|
||||
})
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Populate Tables
|
||||
|
||||
var INPUT_ROW_TEMPLATE = _.template(
|
||||
'<tr class="input" data-fullname="<%- fullname %>">\n' +
|
||||
' <td><%- name %></td>\n' +
|
||||
' <td><input class="enable-btn" type="radio" name="<%- name %>" <% if (enabled) { %>checked="checked"<% } %> /></td>\n' +
|
||||
' <td><input class="disable-btn" type="radio" name="<%- name %>" <% if (!enabled) { %>checked="checked"<% } %> /></td>\n' +
|
||||
'<% if (interval != -1) { %>\n' +
|
||||
' <td><input class="interval-field" type="number" value="<%- interval %>" /></td>\n' +
|
||||
'<% } %>\n' +
|
||||
'<% if (index != -1) { %>\n' +
|
||||
' <% if (index == "") { %>\n' +
|
||||
' <td>' +
|
||||
' <splunk-search-dropdown name="metric_index_selector" id="index-selection" label-field="title" value-field="title" search="| rest services/data/indexes datatype=metric | dedup title | search title!=_* | table title"/>' +
|
||||
' </td>\n' +
|
||||
' <% }else { %>\n' +
|
||||
' <td>' +
|
||||
' <splunk-search-dropdown name="metric_index_selector" id="index-selection" label-field="title" value-field="title" value="<%- index %>" search="| rest services/data/indexes datatype=metric | dedup title | search title!=_* | table title"/>' +
|
||||
' </td>\n' +
|
||||
' <% } %>\n' +
|
||||
'<% } %>\n' +
|
||||
'</tr>\n'
|
||||
)
|
||||
|
||||
// Populate monitor input table
|
||||
var monitorInputs = {}
|
||||
new MonitorInputs(service, {
|
||||
owner: '-',
|
||||
app: 'Splunk_TA_nix',
|
||||
sharing: 'app'
|
||||
}).fetch(function (err, inputs) {
|
||||
var inputsList = _.filter(inputs.list(), function (input) {
|
||||
return input.namespace.app === 'Splunk_TA_nix'
|
||||
})
|
||||
|
||||
_.each(inputsList, function (input) {
|
||||
$('#monitor-input-table').append(
|
||||
$(
|
||||
INPUT_ROW_TEMPLATE({
|
||||
fullname: input.name,
|
||||
name: input.name,
|
||||
enabled: !input.properties().disabled,
|
||||
interval: -1,
|
||||
index: -1
|
||||
})
|
||||
)
|
||||
)
|
||||
monitorInputs[input.name] = input
|
||||
})
|
||||
})
|
||||
|
||||
// Populate scripted Event inputs table
|
||||
var scriptedMetricInputs = {}
|
||||
new ScriptedInputs(service, {
|
||||
owner: '-',
|
||||
app: 'Splunk_TA_nix',
|
||||
sharing: 'app'
|
||||
}).fetch(function (err, inputs) {
|
||||
var inputsList = _.filter(inputs.list(), function (input) {
|
||||
var input_name = input.name
|
||||
.substring(input.name.lastIndexOf('/') + 1)
|
||||
.split('_')
|
||||
return (
|
||||
input.namespace.app === 'Splunk_TA_nix' &&
|
||||
input_name[input_name.length - 1] === 'metric.sh'
|
||||
)
|
||||
})
|
||||
|
||||
_.each(inputsList, function (input) {
|
||||
$('#scripted-metric-input-table').append(
|
||||
$(
|
||||
INPUT_ROW_TEMPLATE({
|
||||
fullname: input.name,
|
||||
name: input.name.substring(input.name.lastIndexOf('/') + 1),
|
||||
enabled: !input.properties().disabled,
|
||||
interval: input.properties().interval,
|
||||
index:
|
||||
input.properties().index === 'default'
|
||||
? ''
|
||||
: input.properties().index
|
||||
})
|
||||
)
|
||||
)
|
||||
scriptedMetricInputs[input.name] = input
|
||||
})
|
||||
})
|
||||
|
||||
// Populate scripted Event inputs table
|
||||
var scriptedEventInputs = {}
|
||||
new ScriptedInputs(service, {
|
||||
owner: '-',
|
||||
app: 'Splunk_TA_nix',
|
||||
sharing: 'app'
|
||||
}).fetch(function (err, inputs) {
|
||||
var inputsList = _.filter(inputs.list(), function (input) {
|
||||
var input_name = input.name
|
||||
.substring(input.name.lastIndexOf('/') + 1)
|
||||
.split('_')
|
||||
return (
|
||||
input.namespace.app === 'Splunk_TA_nix' &&
|
||||
input_name[input_name.length - 1] !== 'metric.sh'
|
||||
)
|
||||
})
|
||||
|
||||
_.each(inputsList, function (input) {
|
||||
$('#scripted-event-input-table').append(
|
||||
$(
|
||||
INPUT_ROW_TEMPLATE({
|
||||
fullname: input.name,
|
||||
name: input.name.substring(input.name.lastIndexOf('/') + 1),
|
||||
enabled: !input.properties().disabled,
|
||||
interval: input.properties().interval,
|
||||
index: -1
|
||||
})
|
||||
)
|
||||
)
|
||||
scriptedEventInputs[input.name] = input
|
||||
})
|
||||
})
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Buttons
|
||||
|
||||
// Enable All button
|
||||
$('.enable-all-btn').click(function (e) {
|
||||
e.preventDefault()
|
||||
var table = $(e.target).closest('.input-table')
|
||||
$('.input .enable-btn', table).prop('checked', true)
|
||||
})
|
||||
|
||||
// Disable All button
|
||||
$('.disable-all-btn').click(function (e) {
|
||||
e.preventDefault()
|
||||
var table = $(e.target).closest('.input-table')
|
||||
$('.input .disable-btn', table).prop('checked', true)
|
||||
})
|
||||
|
||||
// Save button
|
||||
$('#save-btn').click(function (e) {
|
||||
e.preventDefault()
|
||||
if ($('#save-btn').hasClass('disabled')) {
|
||||
return
|
||||
}
|
||||
|
||||
var savesPending = 0
|
||||
var saveErrors = []
|
||||
|
||||
// Save monitor inputs
|
||||
_.each($('#monitor-input-table .input'), function (inputElem) {
|
||||
var fullname = $(inputElem).data('fullname')
|
||||
var enabled = $('.enable-btn', inputElem).prop('checked')
|
||||
|
||||
var input = monitorInputs[fullname]
|
||||
|
||||
savesPending += 1
|
||||
input.update(
|
||||
{
|
||||
disabled: !enabled
|
||||
},
|
||||
saveDone
|
||||
)
|
||||
})
|
||||
|
||||
var invalidIndex = 0 // invalid index flag
|
||||
var invalidInterval = 0 // invalid interval flag
|
||||
var numbers = /^[0-9]+$/
|
||||
// Save scripted Metric inputs
|
||||
_.each($('#scripted-metric-input-table .input'), function (inputElem) {
|
||||
var fullname = $(inputElem).data('fullname')
|
||||
var enabled = $('.enable-btn', inputElem).prop('checked')
|
||||
var interval = $('.interval-field', inputElem).val()
|
||||
var index = $('#index-selection', inputElem)[0].innerText
|
||||
// Handling internationalization transalation due to ticket ADDON-30736
|
||||
if (
|
||||
index.includes('...') ||
|
||||
index.includes('Search produced no results.')
|
||||
) {
|
||||
index = enabled === true ? index : '' // Setting index="" if input is disable, so it allows to save.
|
||||
if (enabled) {
|
||||
invalidIndex = 1
|
||||
}
|
||||
}
|
||||
if (!interval.match(numbers)) {
|
||||
// Check for the interval, Interval must contain only numeric values
|
||||
if (interval.charAt(0) === '-' || interval.includes('.')) {
|
||||
interval = 'invalid'
|
||||
}
|
||||
invalidInterval = 1
|
||||
}
|
||||
var input = scriptedMetricInputs[fullname]
|
||||
savesPending += 1
|
||||
input.update(
|
||||
{
|
||||
disabled: !enabled,
|
||||
interval: interval,
|
||||
index: index
|
||||
},
|
||||
saveDone
|
||||
)
|
||||
})
|
||||
|
||||
// Save scripted Event inputs
|
||||
_.each($('#scripted-event-input-table .input'), function (inputElem) {
|
||||
var fullname = $(inputElem).data('fullname')
|
||||
var enabled = $('.enable-btn', inputElem).prop('checked')
|
||||
var interval = $('.interval-field', inputElem).val()
|
||||
if (!interval.match(numbers)) {
|
||||
if (interval.charAt(0) === '-' || interval.includes('.')) {
|
||||
interval = 'invalid'
|
||||
}
|
||||
invalidInterval = 1
|
||||
}
|
||||
var input = scriptedEventInputs[fullname]
|
||||
savesPending += 1
|
||||
input.update(
|
||||
{
|
||||
disabled: !enabled,
|
||||
interval: interval
|
||||
},
|
||||
saveDone
|
||||
)
|
||||
})
|
||||
|
||||
//Set is_configured=true in app.conf
|
||||
service.post('/services/SetupService', cleaned_data, function (
|
||||
err,
|
||||
response
|
||||
) {
|
||||
if (err) {
|
||||
console.log('Error saving configuration in app.conf')
|
||||
}
|
||||
})
|
||||
|
||||
// After saves are completed...
|
||||
function saveDone (err) {
|
||||
$('#index-not-selected-error').hide()
|
||||
$('#generic-save-error').hide()
|
||||
$('#invalid-interval-error').hide()
|
||||
if (err) {
|
||||
saveErrors.push(err)
|
||||
}
|
||||
|
||||
savesPending -= 1
|
||||
if (savesPending > 0) {
|
||||
return
|
||||
}
|
||||
if (saveErrors.length === 0) {
|
||||
// Save successful. Provide feedback in form of page reload.
|
||||
window.location.reload()
|
||||
} else {
|
||||
// invalid index or interval failure
|
||||
if (invalidIndex || invalidInterval) {
|
||||
if (invalidInterval) {
|
||||
invalidInterval = 0
|
||||
// invalid interval failure
|
||||
$('#invalid-interval-error').show()
|
||||
}
|
||||
if (invalidIndex) {
|
||||
invalidIndex = 0
|
||||
// invalid index failure
|
||||
$('#index-not-selected-error').show()
|
||||
}
|
||||
} else {
|
||||
// Unexpected failure.
|
||||
$('#generic-save-error').show()
|
||||
}
|
||||
|
||||
// (Allow Support to debug if necessary.)
|
||||
console.log('Errors while saving inputs:')
|
||||
console.log(saveErrors)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
34
appserver/static/setup_cloud.js
Normal file
34
appserver/static/setup_cloud.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 Splunk, Inc. <sales@splunk.com>
|
||||
* SPDX-License-Identifier: LicenseRef-Splunk-8-2021
|
||||
*
|
||||
*/
|
||||
|
||||
require([
|
||||
'splunkjs/ready!',
|
||||
'jquery'
|
||||
], function (mvc, $) {
|
||||
var service = mvc.createService()
|
||||
var cleaned_data = {}
|
||||
// Save button
|
||||
$('#save-btn').click(function (e) {
|
||||
e.preventDefault()
|
||||
if ($('#save-btn').hasClass('disabled')) {
|
||||
return
|
||||
}
|
||||
|
||||
//Set is_configured=true in app.conf
|
||||
service.post('/services/SetupService', cleaned_data, function (
|
||||
err,
|
||||
response
|
||||
) {
|
||||
if (err) {
|
||||
console.log('Error saving configuration in app.conf')
|
||||
}
|
||||
else {
|
||||
// Save successful. Provide feedback in form of page reload.
|
||||
window.location.reload()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue