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
);
68 initialLoggingConfig
: initialLoggingConfig
72 putLoggingConfigError(data
) {
73 console
.log("LoggingStore.putLoggingConfigError called. data=", data
);
76 resetLoggingConfigData
= (data
) => {
77 console
.log('LoggingStore.resetLoggingConfigData called. data=', data
);
78 // Do we need to do a deep clone?
79 const loggingConfig
= _cloneDeep(this.initialLoggingConfig
);
81 loggingConfig
: loggingConfig
85 updateCategoryDefaultSeverity
= (catsev
) => {
86 console
.log("LoggingStore.updateCategoryDefaultSeverity:", catsev
);
89 let catIndex
= _findIndex(this.loggingConfig
.defaultSeverities
, function(o
) {
90 return o
.category
== catsev
.category
;
92 console
.log("catIndex=", catIndex
);
94 const loggingConfig
= this.loggingConfig
;
95 loggingConfig
.defaultSeverities
[catIndex
].severity
= catsev
.severity
;
98 loggingConfig
: loggingConfig
101 console
.log("ERROR: catIndex not founds for default category", catsev
.category
);
105 updateCategoryDefaultSyslogSeverity
= (catsev
) => {
106 console
.log("LoggingStore.updateCategoryDefaultSyslogSeverity:", catsev
);
107 // find the category (name) in the syslog sink
110 let loggingConfig
= _cloneDeep(this.loggingConfig
);
111 let syslogSinkIndex
= -1;
112 let nulledCategories
= this.nulledCategories
;
114 loggingConfig
.sinks
&& loggingConfig
.sinks
.map((sink
, sinkIndex
) => {
115 if (sink
.name
== 'syslog') {
117 if (sink
.filter
.category
) {
118 let catIndex
= _findIndex(sink
.filter
.category
, {
121 if (catIndex
!= -1) {
123 if (catsev
.severity
== "") {
124 // blank was selected
125 nulledCategories
.push(catsev
.name
);
127 nulledCategories
: nulledCategories
129 // TODO/NOTE: Can't delete from model as sending a top-level payload with
130 // missing elements is not allowed!
131 // When backend supports it, in loggingSource change the order of operations
132 // // Delete first followed by save/put.
133 _remove(loggingConfig
.sinks
[sinkIndex
].filter
.category
, {
137 sink
.filter
.category
[catIndex
] = catsev
;
140 _remove(nulledCategories
, (v
) => v
== catsev
.name
);
142 nulledCategories
: nulledCategories
144 sink
.filter
.category
.push(catsev
);
147 sink
.filter
.category
= [];
148 sink
.filter
.category
.push(catsev
);
152 sink
.filter
.category
= [];
153 sink
.filter
.category
.push(catsev
);
159 loggingConfig
: loggingConfig
163 updateAllowDuplicateEvents
= (allowFlag
) => {
164 console
.log("LoggingStore.updateAllowDuplicateEvents called. allowFlag=", allowFlag
);
165 const loggingConfig
= this.loggingConfig
;
166 loggingConfig
.allowDuplicateEvents
= allowFlag
;
168 loggingConfig
: loggingConfig
173 * Add a new empty (null) deny event to loggingConfig
175 addDenyEvent
= (event
) => {
176 const loggingConfig
= this.loggingConfig
;
177 loggingConfig
.denyEventIDs
.push(null);
179 loggingConfig
: loggingConfig
186 updateDenyEvent
= (index
, eventID
) => {
187 //console.log("LoggingStore.updateDenyEventID: index=", index);
188 //console.log(" -> eventID=", eventID);
190 const loggingConfig
= this.loggingConfig
;
191 loggingConfig
.denyEventIDs
[index
] = eventID
;
193 loggingConfig
: loggingConfig
200 removeDenyEvent
= (index
) => {
201 // console.log("LoggingStore.removeDenyEvent at index %s", index);
202 const loggingConfig
= this.loggingConfig
;
203 // Note: we are not validating index
204 loggingConfig
.denyEventIDs
.splice(index
, 1);
206 loggingConfig
: loggingConfig
213 updateSyslogViewerURL
= (syslogViewerURL
) => {
214 const loggingConfig
= this.loggingConfig
;
215 loggingConfig
.syslogviewer
= syslogViewerURL
;
217 loggingConfig
: loggingConfig
222 export default alt
.createStore(LoggingStore
, 'LoggingStore');