3 * Copyright 2016 RIFT.IO Inc
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 import _cloneDeep
from 'lodash/cloneDeep';
19 import _findIndex
from 'lodash/findIndex';
20 import _remove
from 'lodash/remove';
21 import LoggingActions
from './loggingActions.js';
22 import LoggingSource
from './loggingSource.js';
24 import alt
from 'widgets/skyquake_container/skyquakeAltInstance';
28 this.loggingConfig
= {};
29 // initialLoggingConfig is the saved state
30 this.initialLoggingConfig
= {};
31 this.nulledCategories
= [];
32 this.bindActions(LoggingActions
);
33 this.registerAsync(LoggingSource
);
34 this.exportPublicMethods({
35 updateCategoryDefaultSeverity
: this.updateCategoryDefaultSeverity
,
36 updateCategoryDefaultSyslogSeverity
: this.updateCategoryDefaultSyslogSeverity
,
37 updateAllowDuplicateEvents
: this.updateAllowDuplicateEvents
,
38 addDenyEvent
: this.addDenyEvent
,
39 updateDenyEvent
: this.updateDenyEvent
,
40 removeDenyEvent
: this.removeDenyEvent
,
41 updateSyslogViewerURL
: this.updateSyslogViewerURL
,
42 resetLoggingConfigData
: this.resetLoggingConfigData
46 getLoggingConfigSuccess
= (data
) => {
47 console
.log("LoggingStore.getLoggingConfigSuccess called. data=", data
);
48 // Do we need to do a deep clone?
49 const initialLoggingConfig
= _cloneDeep(data
);
50 console
.log("initialLoggingConfig=", initialLoggingConfig
);
53 initialLoggingConfig
: initialLoggingConfig
,
58 getLoggingConfigError(data
) {
59 console
.log("LoggongStore.getLoggingConfigError called. data=", data
);
62 putLoggingConfigSuccess
= (data
) => {
63 console
.log("LoggingStore.putLoggingConfigSuccess called. data=", data
);
64 const initialLoggingConfig
= _cloneDeep(this.loggingConfig
);
67 initialLoggingConfig
: initialLoggingConfig
71 putLoggingConfigError(data
) {
72 console
.log("LoggingStore.putLoggingConfigError called. data=", data
);
75 resetLoggingConfigData
= (data
) => {
76 console
.log('LoggingStore.resetLoggingConfigData called. data=', data
);
77 // Do we need to do a deep clone?
78 const loggingConfig
= _cloneDeep(this.initialLoggingConfig
);
80 loggingConfig
: loggingConfig
84 updateCategoryDefaultSeverity
= (catsev
) => {
85 console
.log("LoggingStore.updateCategoryDefaultSeverity:", catsev
);
88 let catIndex
= _findIndex(this.loggingConfig
.defaultSeverities
, function(o
) {
89 return o
.category
== catsev
.category
;
91 console
.log("catIndex=", catIndex
);
93 const loggingConfig
= this.loggingConfig
;
94 loggingConfig
.defaultSeverities
[catIndex
].severity
= catsev
.severity
;
97 loggingConfig
: loggingConfig
100 console
.log("ERROR: catIndex not founds for default category", catsev
.category
);
104 updateCategoryDefaultSyslogSeverity
= (catsev
) => {
105 console
.log("LoggingStore.updateCategoryDefaultSyslogSeverity:", catsev
);
106 // find the category (name) in the syslog sink
109 let loggingConfig
= _cloneDeep(this.loggingConfig
);
110 let syslogSinkIndex
= -1;
111 let nulledCategories
= this.nulledCategories
;
113 loggingConfig
.sinks
&& loggingConfig
.sinks
.map((sink
, sinkIndex
) => {
114 if (sink
.name
== 'syslog') {
116 if (sink
.filter
.category
) {
117 let catIndex
= _findIndex(sink
.filter
.category
, {
120 if (catIndex
!= -1) {
122 if (catsev
.severity
== "") {
123 // blank was selected
124 nulledCategories
.push(catsev
.name
);
126 nulledCategories
: nulledCategories
128 // TODO/NOTE: Can't delete from model as sending a top-level payload with
129 // missing elements is not allowed!
130 // When backend supports it, in loggingSource change the order of operations
131 // // Delete first followed by save/put.
132 _remove(loggingConfig
.sinks
[sinkIndex
].filter
.category
, {
136 sink
.filter
.category
[catIndex
] = catsev
;
139 _remove(nulledCategories
, (v
) => v
== catsev
.name
);
141 nulledCategories
: nulledCategories
143 sink
.filter
.category
.push(catsev
);
146 sink
.filter
.category
= [];
147 sink
.filter
.category
.push(catsev
);
151 sink
.filter
.category
= [];
152 sink
.filter
.category
.push(catsev
);
158 loggingConfig
: loggingConfig
162 updateAllowDuplicateEvents
= (allowFlag
) => {
163 console
.log("LoggingStore.updateAllowDuplicateEvents called. allowFlag=", allowFlag
);
164 const loggingConfig
= this.loggingConfig
;
165 loggingConfig
.allowDuplicateEvents
= allowFlag
;
167 loggingConfig
: loggingConfig
172 * Add a new empty (null) deny event to loggingConfig
174 addDenyEvent
= (event
) => {
175 const loggingConfig
= this.loggingConfig
;
176 loggingConfig
.denyEventIDs
.push(null);
178 loggingConfig
: loggingConfig
185 updateDenyEvent
= (index
, eventID
) => {
186 //console.log("LoggingStore.updateDenyEventID: index=", index);
187 //console.log(" -> eventID=", eventID);
189 const loggingConfig
= this.loggingConfig
;
190 loggingConfig
.denyEventIDs
[index
] = eventID
;
192 loggingConfig
: loggingConfig
199 removeDenyEvent
= (index
) => {
200 // console.log("LoggingStore.removeDenyEvent at index %s", index);
201 const loggingConfig
= this.loggingConfig
;
202 // Note: we are not validating index
203 loggingConfig
.denyEventIDs
.splice(index
, 1);
205 loggingConfig
: loggingConfig
212 updateSyslogViewerURL
= (syslogViewerURL
) => {
213 const loggingConfig
= this.loggingConfig
;
214 loggingConfig
.syslogviewer
= syslogViewerURL
;
216 loggingConfig
: loggingConfig
221 export default alt
.createStore(LoggingStore
, 'LoggingStore');