Skip to content

Commit

Permalink
Merge pull request splunk#6 from ziegfried/setup-view
Browse files Browse the repository at this point in the history
Setup view
  • Loading branch information
ziegfried authored Jun 16, 2020
2 parents 2f414b3 + 024a272 commit 3085024
Show file tree
Hide file tree
Showing 35 changed files with 4,214 additions and 113 deletions.
3 changes: 3 additions & 0 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ['@splunk/babel-preset'],
};
6 changes: 6 additions & 0 deletions .github/actions/appinspect/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ inputs:
splunkPassword:
description: Splunk.com password used to login to the appinspect API
required: true
includedTags:
description: Comma separated list of tags to include in appinspect job
required: false
excludedTags:
description: Comma separated list of tags to exclude from appinspect job
required: false
15 changes: 11 additions & 4 deletions .github/actions/appinspect/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ const core_1 = __webpack_require__(470);
const fs = __importStar(__webpack_require__(747));
const api_1 = __webpack_require__(85);
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
function appInspect({ user, password, filePath, }) {
function appInspect({ user, password, filePath, includedTags, excludedTags, }) {
return __awaiter(this, void 0, void 0, function* () {
core_1.info(`Submitting file ${filePath} to appinspect API...`);
if (!fs.existsSync(filePath)) {
Expand All @@ -488,8 +488,8 @@ function appInspect({ user, password, filePath, }) {
const submitRes = yield api_1.submit({
filePath,
token,
// includedTags: ['cloud'],
excludedTags: ['cloud'],
includedTags,
excludedTags,
});
const reqId = submitRes.request_id;
core_1.info(`Submitted and received reqId=${reqId}`);
Expand Down Expand Up @@ -548,13 +548,20 @@ function appInspect({ user, password, filePath, }) {
}
});
}
const splitTags = (value) => {
if (value) {
return value.trim().split(/\s*,\s*/);
}
};
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const filePath = core_1.getInput('filePath');
const user = core_1.getInput('splunkUser');
const password = core_1.getInput('splunkPassword');
yield appInspect({ user, password, filePath });
const includedTags = splitTags(core_1.getInput('includedTags'));
const excludedTags = splitTags(core_1.getInput('includedTags'));
yield appInspect({ user, password, filePath, includedTags, excludedTags });
}
catch (error) {
core_1.setFailed(error.message);
Expand Down
18 changes: 15 additions & 3 deletions .github/actions/appinspect/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ async function appInspect({
user,
password,
filePath,
includedTags,
excludedTags,
}: {
filePath: string;
user: string;
password: string;
includedTags?: string[];
excludedTags?: string[];
}): Promise<void> {
info(`Submitting file ${filePath} to appinspect API...`);
if (!fs.existsSync(filePath)) {
Expand All @@ -22,8 +26,8 @@ async function appInspect({
const submitRes: SubmitResponse = await submit({
filePath,
token,
// includedTags: ['cloud'],
excludedTags: ['cloud'],
includedTags,
excludedTags,
});

const reqId = submitRes.request_id;
Expand Down Expand Up @@ -96,13 +100,21 @@ async function appInspect({
}
}

const splitTags = (value: string | null | undefined): string[] | undefined => {
if (value) {
return value.trim().split(/\s*,\s*/);
}
};

async function run(): Promise<void> {
try {
const filePath: string = getInput('filePath');
const user = getInput('splunkUser');
const password = getInput('splunkPassword');
const includedTags = splitTags(getInput('includedTags'));
const excludedTags = splitTags(getInput('includedTags'));

await appInspect({ user, password, filePath });
await appInspect({ user, password, filePath, includedTags, excludedTags });
} catch (error) {
setFailed(error.message);
}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/appinspect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ jobs:
filePath: ./dist/slack-alerts.spl
splunkUser: ${{ secrets.SPLUNKBASE_USER }}
splunkPassword: ${{ secrets.SPLUNKBASE_PASSWORD }}
includedTags: cloud
30 changes: 25 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,44 @@
"description": "Slack alert action for Splunk Enterprise",
"private": true,
"splunk": {
"appName": "slack_alerts"
"appName": "slack_alerts",
"appSource": "src/app"
},
"repository": "[email protected]:ziegfried/splunk-slack-alerts.git",
"author": "Siegfried Puchbauer <[email protected]>",
"license": "Apache-2.0",
"dependencies": {
"@splunk/react-page": "^3.0.0",
"@splunk/react-toast-notifications": "^0.7.0",
"@splunk/react-ui": "^2",
"react": "^16",
"react-dom": "^16",
"styled-components": "^4"
},
"devDependencies": {
"@babel/core": "^7",
"@splunk/babel-preset": "^3.0.0",
"@splunk/webpack-configs": "^5.0.0",
"babel-loader": "^8.0.4",
"onchange": "^3.2.1",
"splunk-slap": "^0.0.6"
"prettier": "^2.0.5",
"splunk-slap": "^0.0.6",
"webpack": "^4.16.2",
"webpack-cli": "^3.1.0",
"webpack-livereload-plugin": "^2.1.1",
"webpack-merge": "^4.1.3"
},
"scripts": {
"setup": "yarn install && yarn build && yarn symlink",
"build": "slap stage",
"build:pages": "webpack --config=src/ui/webpack.config.js --bail",
"slap:post-stage": "yarn build:pages",
"symlink": "slap symlink",
"package": "slap package --prod",
"pkg": "yarn package",
"rebuild": "echo \"Rebuilding...\" && slap stage --skip-clean",
"start": "yarn build && onchange src/main/resources/splunk/** -- slap stage",
"test": "python -m unittest discover -s src/main/resources/splunk/bin -p '*_tests.py' -v",
"test:watch": "onchange src/main/resources/splunk/bin/** -- yarn test"
"start": "yarn build && onchange src/** -- slap stage",
"test": "python -m unittest discover -s src/app/bin -p '*_tests.py' -v",
"test:watch": "onchange src/app/bin/** -- yarn test"
}
}
48 changes: 26 additions & 22 deletions src/main/resources/splunk/README.md → src/app/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
# Slack Notification Alerts

This app contains a Splunk custom alert action which allows you to send messages to Slack channels.

## System requirements

* Splunk version 6.3 or greater
* Windows, Linux or Mac OS operating system
- Splunk version 6.3 or greater
- Windows, Linux or Mac OS operating system

## Installation

App installation requires admin priviledges.
App installation requires admin privileges.

* Navigate to "Manage apps" and click "Install app from file"
* Upload the app bundle
- Navigate to "Manage apps" and click "Install app from file"
- Upload the app bundle

## Configuration

Expand All @@ -21,26 +17,34 @@ In order to setup the app, navigate to "Settings" -> "Alert actions". Click on "
On the setup screen you'll want to supply a Webhook URL. You can obtain this URL by configuring a
custom integration for you Slack workspace.

For more information see https://api.slack.com/incoming-webhooks
For more information see https://slack.com/apps/A0F7XDUAZ-incoming-webhooks

## Troubleshooting

### Known issue with Setup

> Setup page shows "I am Legend" setup_stub
An issue after upgrading the Slack Alerts app can cause an invalid redirect from the alert actions listing page to the setup page. Go to "Manage Apps" and click on "Set up" instead of using the Alert actions listing.

Alternatively - to fix it - you can remove the `is_configured` flag from `$SPLUNK_HOME/etc/apps/slack_alerts/local/app.conf` and restart Splunk.

### Logs

In order to investigate problems with the Slack alert action, you can check the logs of the
alert action.

* Navigate to "Settings" -> "Alert actions"
* Click on "View log events" for the Slack alert action
- Navigate to "Settings" -> "Alert actions"
- Click on "View log events" for the Slack alert action

You can also increase the verbosity of logs generated by the alert action by adjusting the

* Navigate to "Settings" -> "Server settings" -> "Server logging"
* Search for the log channel "sendmodalert"
* Select logging level "DEBUG"
- Navigate to "Settings" -> "Server settings" -> "Server logging"
- Search for the log channel "sendmodalert"
- Select logging level "DEBUG"

**NOTE**: This will increase cause detailed logs to be produced for all alert actions and might have an
inpact on system performance. It is not recommended to do this on a production system.
impact on system performance. It is not recommended to do this on a production system.

### Manually trigger the alert action

Expand All @@ -60,24 +64,24 @@ In case of an error when manually triggering the Slack alert action, you'll noti

Here are the possible error codes returned by the slack alert action:

* Error Code **`2`**: Validation Failed
- Error Code **`2`**: Validation Failed

This error code indications that the parameters handed to the alert action were invalid. Check the configuration.

* Error Code **`3`**: Channel not found
- Error Code **`3`**: Channel not found

This error code is returned if the given Slack channel was not found

* Error Code **`4`**: Forbidden
- Error Code **`4`**: Forbidden

Slack indicates that sending the message to the given channel is not allowed. Contact your Slack workspace administrator to find out about possible restrictions.

* Error Code **`5`**: HTTP failure
- Error Code **`5`**: HTTP failure

This error code indicates a problem with executing the HTTP request to the configured webhook URL. Possible reasons include network issues, proxy server issues
See logs for details.

* Error Code **`6`**: Unexpected error
- Error Code **`6`**: Unexpected error

An unexpected error occured while attempting to send the slack message.
An unexpected error occurred while attempting to send the slack message.
See logs for details.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
23 changes: 23 additions & 0 deletions src/app/appserver/templates/setup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>
Slack Alerts Setup
</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" href="apple-touch-icon.png">
</head>
<body>
<script src="${make_url('/config?autoload=1')}" crossorigin="use-credentials"></script>
<script src="${make_url('/static/js/i18n.js')}"></script>
<script src="${make_url('/i18ncatalog?autoload=1')}"></script>
<%
page_path = "/static/app/slack_alerts/pages/slack_alerts_setup.js"
common_path = "/static/app/slack_alerts/pages/common.js"
%>
<script src="${make_url(common_path)}"></script>
<script src="${make_url(page_path)}"></script>
</body>
</html>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
[ui]
is_visible = 0
is_visible = 1
show_in_nav = 0
label = Slack Alerts
setup_view = slack_alerts_setup

[launcher]
author = Siegfried Puchbauer
description = Custom alert action to send messages to Slack channels
version = 0.0.0

[install]
is_configured = 0

[package]
id = slack_alerts
File renamed without changes.
3 changes: 3 additions & 0 deletions src/app/default/data/ui/nav/default.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<nav search_view="search">
<view name="slack_alerts_setup" default="true" />
</nav>
4 changes: 4 additions & 0 deletions src/app/default/data/ui/views/slack_alerts_setup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<view template="slack_alerts:/templates/setup.html" type="html">
<label>Slack Alerts Setup</label>
</view>
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
41 changes: 0 additions & 41 deletions src/main/resources/splunk/default/setup.xml

This file was deleted.

Loading

0 comments on commit 3085024

Please sign in to comment.