Skip to content

Commit

Permalink
Merge pull request #28 from Security-Onion-Solutions/2.3.51
Browse files Browse the repository at this point in the history
2.3.51
  • Loading branch information
TOoSmOotH authored May 21, 2021
2 parents 146305f + 682b783 commit 6aae922
Show file tree
Hide file tree
Showing 15 changed files with 249 additions and 135 deletions.
3 changes: 2 additions & 1 deletion agent/modules/importer/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"os/exec"
"time"
"github.com/apex/log"
"github.com/kennygrant/sanitize"
"github.com/security-onion-solutions/securityonion-soc/agent"
"github.com/security-onion-solutions/securityonion-soc/model"
"github.com/security-onion-solutions/securityonion-soc/module"
Expand Down Expand Up @@ -117,7 +118,7 @@ func (importer *Importer) ProcessJob(job *model.Job, reader io.ReadCloser) (io.R
}

func (importer *Importer) CleanupJob(job *model.Job) {
pcapOutputFilepath := fmt.Sprintf("%s/%d.%s", importer.pcapOutputPath, job.Id, job.FileExtension)
pcapOutputFilepath := fmt.Sprintf("%s/%d.%s", importer.pcapOutputPath, job.Id, sanitize.Name(job.FileExtension))
os.Remove(pcapOutputFilepath)
}

Expand Down
3 changes: 2 additions & 1 deletion agent/modules/stenoquery/stenoquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

"github.com/apex/log"
"github.com/kennygrant/sanitize"
"github.com/security-onion-solutions/securityonion-soc/agent"
"github.com/security-onion-solutions/securityonion-soc/model"
"github.com/security-onion-solutions/securityonion-soc/module"
Expand Down Expand Up @@ -139,7 +140,7 @@ func (steno *StenoQuery) ProcessJob(job *model.Job, reader io.ReadCloser) (io.Re
}

func (steno *StenoQuery) CleanupJob(job *model.Job) {
pcapOutputFilepath := fmt.Sprintf("%s/%d.%s", steno.pcapOutputPath, job.Id, job.FileExtension)
pcapOutputFilepath := fmt.Sprintf("%s/%d.%s", steno.pcapOutputPath, job.Id, sanitize.Name(job.FileExtension))
os.Remove(pcapOutputFilepath)
}

Expand Down
15 changes: 9 additions & 6 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ <h2>{{ i18n.viewJob }}</h2>
<h2 v-text="i18n.grid"></h2>
</v-col>
<v-col cols="3" align="end">
<h4>{{ i18n.gridEps }} {{ gridEps | formatCount }}</h4>
<h4 v-if="metricsEnabled">{{ i18n.gridEps }} {{ gridEps | formatCount }}</h4>
</v-col>
</v-row>
<v-row>
Expand Down Expand Up @@ -1088,7 +1088,10 @@ <h4>{{ i18n.gridEps }} {{ gridEps | formatCount }}</h4>
<td v-text="props.item.description"></td>
<td v-text="props.item.version"></td>
<td v-text="props.item.model"></td>
<td>{{ props.item.productionEps | formatCount }}</td>
<td v-if="metricsEnabled">
<span v-if="props.item.metricsEnabled">{{ props.item.productionEps | formatCount }}</span>
<span v-if="!props.item.metricsEnabled">{{ i18n.na }}</span>
</td>
<td>{{ props.item.updateTime | formatTimestamp }}</td>
<td>{{ props.item.epochTime | formatTimestamp }}</td>
<td>{{ props.item.uptimeSeconds | formatDuration }}</td>
Expand All @@ -1112,23 +1115,23 @@ <h4>{{ i18n.gridEps }} {{ gridEps | formatCount }}</h4>
<span class="filter label">{{ i18n.dateOnline }}</span>
<span class="filter value">{{ item.onlineTime | formatDateTime }}</span>
</div>
<div>
<div v-if="item.metricsEnabled">
<span class="filter label">{{ i18n.epsProduction }}</span>
<span class="filter value">{{ item.productionEps | formatCount }}</span>
</div>
<div>
<div v-if="item.metricsEnabled">
<span class="filter label">{{ i18n.epsConsumption }}</span>
<span class="filter value">{{ item.consumptionEps | formatCount }}</span>
</div>
<div>
<div v-if="item.metricsEnabled">
<span class="filter label">{{ i18n.nodeStatusProcess }}</span>
<span class="filter value">{{ $root.localizeMessage(item.processStatus) }}</span>
</div>
<div>
<span class="filter label">{{ i18n.nodeStatusConnection }}</span>
<span class="filter value">{{ $root.localizeMessage(item.connectionStatus) }}</span>
</div>
<div>
<div v-if="item.metricsEnabled">
<span class="filter label">{{ i18n.nodeStatusRaid }}</span>
<span class="filter value">{{ $root.localizeMessage(item.raidStatus) }}</span>
</div>
Expand Down
1 change: 1 addition & 0 deletions html/js/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ const i18n = {
months: 'months',
mruQuery: 'Recently Used',
mruQueryHelp: 'This query is a user-defined query and is only available on this browser.',
na: 'N/A',
noData: 'No information is currently available.',
nodeExpandHelp: 'Show node details',
nodeExpand: 'Expand',
Expand Down
21 changes: 21 additions & 0 deletions html/js/routes/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ routes.push({ path: '/grid', name: 'grid', component: {
itemsPerPage: 10,
footerProps: { 'items-per-page-options': [10,25,50,100,250,1000] },
gridEps: 0,
metricsEnabled: false,
}},
created() {
Vue.filter('colorNodeStatus', this.colorNodeStatus);
Expand Down Expand Up @@ -70,6 +71,7 @@ routes.push({ path: '/grid', name: 'grid', component: {
this.nodes.forEach(function(node) {
route.updateNode(node);
});
this.updateMetricsEnabled();
this.loadLocalSettings();
} catch (error) {
this.$root.showError(error);
Expand All @@ -78,6 +80,21 @@ routes.push({ path: '/grid', name: 'grid', component: {
this.$root.subscribe("node", this.updateNode);
this.$root.subscribe("status", this.updateStatus);
},
updateMetricsEnabled() {
this.metricsEnabled = !this.nodes.every(function(node) { return !node.metricsEnabled; });

const route = this;
const epsColumn = this.headers.find(function(item) {
return item.text == route.i18n.eps
});
if (epsColumn) {
if (!this.metricsEnabled) {
epsColumn.align = ' d-none';
} else {
epsColumn.align = '';
}
}
},
expand(item) {
if (this.isExpanded(item)) {
this.expanded = [];
Expand All @@ -101,6 +118,10 @@ routes.push({ path: '/grid', name: 'grid', component: {
}
},
updateNode(node) {
this.updateNodeDetails(node);
this.updateMetricsEnabled()
},
updateNodeDetails(node) {
var found = false;
for (var i = 0; i < this.nodes.length; i++) {
if (this.nodes[i].id == node.id) {
Expand Down
26 changes: 26 additions & 0 deletions html/js/routes/grid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,29 @@ test('updateStatus', () => {
comp.updateStatus(status);
expect(comp.gridEps).toBe(12);
});

test('updateMetricsEnabled', () => {
testUpdateMetricsEnabled(true, false, true);
testUpdateMetricsEnabled(false, false, false);
testUpdateMetricsEnabled(true, true, true);
});

function testUpdateMetricsEnabled(node1MetricsEnabled, node2MetricsEnabled, expectedMetricsEnabled) {
const node1 = { metricsEnabled: node1MetricsEnabled };
const node2 = { metricsEnabled: node2MetricsEnabled };
comp.nodes = [node1, node2];

comp.updateMetricsEnabled();

expect(comp.metricsEnabled).toBe(expectedMetricsEnabled);

const epsColumn = comp.headers.find(function(item) {
return item.text == comp.i18n.eps;
});

if (!expectedMetricsEnabled) {
expect(epsColumn.align).toBe(' d-none');
} else {
expect(epsColumn.align).toBe('');
}
}
12 changes: 12 additions & 0 deletions model/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package model

import (
"strings"
"time"
)

Expand Down Expand Up @@ -45,6 +46,17 @@ func NewJob() *Job {
}
}

func (job *Job) SetNodeId(nodeId string) {
job.NodeId = strings.ToLower(nodeId)
}

func (job *Job) GetNodeId() string {
// Lower case on the Getter as well since the property could have been
// manipulated directly. Consider json.Unmarshall().
job.NodeId = strings.ToLower(job.NodeId)
return job.NodeId
}

func (job *Job) Complete() {
job.Status = JobStatusCompleted
job.CompleteTime = time.Now()
Expand Down
39 changes: 39 additions & 0 deletions model/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,42 @@ func TestVerifyJob(tester *testing.T) {
tester.Errorf("expected Status %d but got %d", JobStatusCompleted, job.Status)
}
}

func TestSetNodeId(tester *testing.T) {
job := NewJob()
if job.NodeId != "" {
tester.Errorf("expected new jobs to have an empty node ID")
}

job.NodeId = "test"
if job.NodeId != "test" {
tester.Errorf("expected unmodified Node ID but got %s", job.NodeId)
}

job.SetNodeId("testing")
if job.NodeId != "testing" {
tester.Errorf("expected unmodified Node ID but got %s", job.NodeId)
}
if job.GetNodeId() != "testing" {
tester.Errorf("expected unmodified Node ID via getter but got %s", job.GetNodeId())
}

job.SetNodeId("TestingThis")
if job.NodeId != "testingthis" {
tester.Errorf("expected lowercased Node ID but got %s", job.NodeId)
}
if job.GetNodeId() != "testingthis" {
tester.Errorf("expected lowercased Node ID via getter but got %s", job.GetNodeId())
}

job.NodeId = "TestingThis2"
if job.NodeId != "TestingThis2" {
tester.Errorf("expected unmodified Node ID but got %s", job.NodeId)
}
if job.GetNodeId() != "testingthis2" {
tester.Errorf("expected lowercased Node ID via getter but got %s", job.GetNodeId())
}
if job.NodeId != "testingthis2" {
tester.Errorf("expected lowercased Node ID after getter but got %s", job.NodeId)
}
}
12 changes: 8 additions & 4 deletions model/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Node struct {
ProductionEps int `json:"productionEps"`
ConsumptionEps int `json:"consumptionEps"`
FailedEvents int `json:"failedEvents"`
MetricsEnabled bool `json:"metricsEnabled"`
}

func NewNode(id string) *Node {
Expand Down Expand Up @@ -79,19 +80,22 @@ func (node *Node) updateStatusComponent(currentState string, newState string) st
return currentState
}

func (node *Node) UpdateOverallStatus() bool {
func (node *Node) UpdateOverallStatus(enhancedStatusEnabled bool) bool {
newStatus := NodeStatusUnknown
newStatus = node.updateStatusComponent(newStatus, node.ConnectionStatus)
newStatus = node.updateStatusComponent(newStatus, node.RaidStatus)
newStatus = node.updateStatusComponent(newStatus, node.ProcessStatus)
if enhancedStatusEnabled {
newStatus = node.updateStatusComponent(newStatus, node.RaidStatus)
newStatus = node.updateStatusComponent(newStatus, node.ProcessStatus)
}

// Special case: If either process or connection status is unknown then show node in error state.
if (node.Role != "so-import" && node.ProcessStatus == NodeStatusUnknown) ||
if (enhancedStatusEnabled && node.ProcessStatus == NodeStatusUnknown) ||
node.ConnectionStatus == NodeStatusUnknown {
newStatus = NodeStatusFault
}

oldStatus := node.Status
node.Status = newStatus
node.MetricsEnabled = enhancedStatusEnabled
return oldStatus != node.Status
}
Loading

0 comments on commit 6aae922

Please sign in to comment.