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 _
from 'lodash';
19 import LoggingActions
from './loggingActions.js';
20 import LoggingSource
from './loggingSource.js';
22 import alt
from 'widgets/skyquake_container/skyquakeAltInstance';
26 this.loggingConfig
= {};
27 // initialLoggingConfig is the saved state
28 this.initialLoggingConfig
= {};
29 this.nulledCategories
= [];
30 this.bindActions(LoggingActions
);
31 this.registerAsync(LoggingSource
);
32 this.exportPublicMethods({
33 updateCategoryDefaultSeverity
: this.updateCategoryDefaultSeverity
,
34 updateCategoryDefaultSyslogSeverity
: this.updateCategoryDefaultSyslogSeverity
,
35 updateAllowDuplicateEvents
: this.updateAllowDuplicateEvents
,
36 addDenyEvent
: this.addDenyEvent
,
37 updateDenyEvent
: this.updateDenyEvent
,
38 removeDenyEvent
: this.removeDenyEvent
,
39 updateSyslogViewerURL
: this.updateSyslogViewerURL
,
40 resetLoggingConfigData
: this.resetLoggingConfigData
44 getLoggingConfigSuccess
= (data
) => {
45 console
.log("LoggingStore.getLoggingConfigSuccess called. data=", data
);
46 // Do we need to do a deep clone?
47 const initialLoggingConfig
= _
.cloneDeep(data
);
48 console
.log("initialLoggingConfig=", initialLoggingConfig
);
51 initialLoggingConfig
: initialLoggingConfig
,
56 getLoggingConfigError(data
) {
57 console
.log("LoggongStore.getLoggingConfigError called. data=", data
);
60 putLoggingConfigSuccess
= (data
) => {
61 console
.log("LoggingStore.putLoggingConfigSuccess called. data=", data
);
62 const initialLoggingConfig
= _
.cloneDeep(this.loggingConfig
);
65 initialLoggingConfig
: initialLoggingConfig
69 putLoggingConfigError(data
) {
70 console
.log("LoggingStore.putLoggingConfigError called. data=", data
);
73 resetLoggingConfigData
= (data
) => {
74 console
.log('LoggingStore.resetLoggingConfigData called. data=', data
);
75 // Do we need to do a deep clone?
76 const loggingConfig
= _
.cloneDeep(this.initialLoggingConfig
);
78 loggingConfig
: loggingConfig
82 updateCategoryDefaultSeverity
= (catsev
) => {
83 console
.log("LoggingStore.updateCategoryDefaultSeverity:", catsev
);
86 let catIndex
= _
.findIndex(this.loggingConfig
.defaultSeverities
, function(o
) {
87 return o
.category
== catsev
.category
;
89 console
.log("catIndex=", catIndex
);
91 const loggingConfig
= this.loggingConfig
;
92 loggingConfig
.defaultSeverities
[catIndex
].severity
= catsev
.severity
;
95 loggingConfig
: loggingConfig
98 console
.log("ERROR: catIndex not founds for default category", catsev
.category
);
102 updateCategoryDefaultSyslogSeverity
= (catsev
) => {
103 console
.log("LoggingStore.updateCategoryDefaultSyslogSeverity:", catsev
);
104 // find the category (name) in the syslog sink
107 let loggingConfig
= _
.cloneDeep(this.loggingConfig
);
108 let syslogSinkIndex
= -1;
109 let nulledCategories
= this.nulledCategories
;
111 loggingConfig
.sinks
&& loggingConfig
.sinks
.map((sink
, sinkIndex
) => {
112 if (sink
.name
== 'syslog') {
114 if (sink
.filter
.category
) {
115 let catIndex
= _
.findIndex(sink
.filter
.category
, {
118 if (catIndex
!= -1) {
120 if (catsev
.severity
== "") {
121 // blank was selected
122 nulledCategories
.push(catsev
.name
);
124 nulledCategories
: nulledCategories
126 // TODO/NOTE: Can't delete from model as sending a top-level payload with
127 // missing elements is not allowed!
128 // When backend supports it, in loggingSource change the order of operations
129 // // Delete first followed by save/put.
130 // _.remove(loggingConfig.sinks[sinkIndex].filter.category, {
134 sink
.filter
.category
[catIndex
] = catsev
;
137 _
.remove(nulledCategories
, (v
) => v
== catsev
.name
);
139 nulledCategories
: nulledCategories
141 sink
.filter
.category
.push(catsev
);
144 sink
.filter
.category
= [];
145 sink
.filter
.category
.push(catsev
);
149 sink
.filter
.category
= [];
150 sink
.filter
.category
.push(catsev
);
156 loggingConfig
: loggingConfig
160 updateAllowDuplicateEvents
= (allowFlag
) => {
161 console
.log("LoggingStore.updateAllowDuplicateEvents called. allowFlag=", allowFlag
);
162 const loggingConfig
= this.loggingConfig
;
163 loggingConfig
.allowDuplicateEvents
= allowFlag
;
165 loggingConfig
: loggingConfig
170 * Add a new empty (null) deny event to loggingConfig
172 addDenyEvent
= (event
) => {
173 const loggingConfig
= this.loggingConfig
;
174 loggingConfig
.denyEventIDs
.push(null);
176 loggingConfig
: loggingConfig
183 updateDenyEvent
= (index
, eventID
) => {
184 //console.log("LoggingStore.updateDenyEventID: index=", index);
185 //console.log(" -> eventID=", eventID);
187 const loggingConfig
= this.loggingConfig
;
188 loggingConfig
.denyEventIDs
[index
] = eventID
;
190 loggingConfig
: loggingConfig
197 removeDenyEvent
= (index
) => {
198 // console.log("LoggingStore.removeDenyEvent at index %s", index);
199 const loggingConfig
= this.loggingConfig
;
200 // Note: we are not validating index
201 loggingConfig
.denyEventIDs
.splice(index
, 1);
203 loggingConfig
: loggingConfig
210 updateSyslogViewerURL
= (syslogViewerURL
) => {
211 const loggingConfig
= this.loggingConfig
;
212 loggingConfig
.syslogviewer
= syslogViewerURL
;
214 loggingConfig
: loggingConfig
219 export default alt
.createStore(LoggingStore
);