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 let rw
= require('utils/rw.js');
19 var API_SERVER
= rw
.getSearchParams(window
.location
).api_server
;
20 var loggingActions
= require('./loggingActions.js');
21 var Utils
= require('utils/utils.js');
22 import $ from 'jquery';
24 function apiUrl(endpoint
) {
25 return endpoint
.replace(/\/$/,'') + '?api_server=' + API_SERVER
;
30 * Retrieve the logging configuration data from the Node API server
32 getLoggingConfig: function() {
33 //console.log("LoggingSource.getLoggingConfig called");
35 remote: function(state
) {
36 return new Promise(function(resolve
, reject
) {
37 //console.log("loggingSource.getLoggingConfig called");
39 url
: apiUrl('api/aggregate'),
41 beforeSend
: Utils
.addAuthorizationStub
,
42 success: function(data
) {
43 //console.log("LoggingSource.getLoggingConfig success call. data=", data);
47 console
.log("Error getting logging config details");
52 success
: loggingActions
.getLoggingConfigSuccess
,
53 error
: loggingActions
.getLoggingConfigError
57 * Update the logging configuration data on the server
58 * @param {object} state - Reference to parent store state
59 * @param {object} loggingConfig - logging configuration data
60 * @return {[type]} [description]
63 updateLoggingConfig: function () {
65 remote: function(state
, nulledCategories
, loggingConfig
) {
66 return new Promise(function(resolve
, reject
) {
69 if(loggingConfig
.hasOwnProperty('allowDuplicateEvents')) {
70 promises
.push($.ajax({
71 url
: apiUrl('api/config/allow-duplicate-events'),
73 beforeSend
: Utils
.addAuthorizationStub
,
75 allowDuplicateEvents
: loggingConfig
.allowDuplicateEvents
77 success: function(data
) {
80 error: function(error
) {
81 console
.log("There was an error updating the logging config data",
87 // if(nulledCategories.length > 0) {
89 // // url: apiUrl('api/config/default-severity'),
90 // url: apiUrl('api/config/default-syslog-severity/' + nulledCategories.join(',')),
92 // beforeSend: Utils.addAuthorizationStub,
93 // success: function(data) {
96 // error: function(error) {
97 // console.log("There was an error updating the logging config data",
102 // promises.push(remove);
104 Promise
.all(promises
).then(function(data
) {
106 url
: apiUrl('api/aggregate'),
108 beforeSend
: Utils
.addAuthorizationStub
,
110 success: function(data
) {
113 error: function(error
) {
114 console
.log("There was an error updating the logging config data",
119 }).then(function(data
){
128 success
: loggingActions
.putLoggingConfigSuccess
,
129 error
: loggingActions
.putLoggingConfigError