@@ -3,39 +3,39 @@ import './App.css';
33import './Theme.css' ;
44import './fonts/technology-icons-gh-pages/styles/technology-icons.css' ;
55import './fonts/glyphter/css/Glyphter.css' ;
6- import {
7- Settings ,
8- Paper ,
9- Loading ,
10- RequestBar ,
11- Menu ,
12- Login ,
13- Overlay ,
14- Message ,
15- ContentWrapper
16- } from './components' ;
17- import { Route , Switch } from 'react-router-dom' ;
6+ import { ContentWrapper , Loading , Login , Menu , Message , Overlay , Paper , RequestBar , Settings } from './components' ;
7+ import { Route , Switch , withRouter } from 'react-router-dom' ;
188import { connect } from 'react-redux' ;
19- import { withRouter } from 'react-router-dom' ;
20- import { setSupported , setConfig , addRequest , clearAllMessage , setControlVisibility , setUserId , setUserData , pushMessage , setCounterInfo , setAlert } from './actions' ;
9+ import {
10+ addRequest ,
11+ clearAllMessage ,
12+ pushMessage ,
13+ setAlert ,
14+ setConfig ,
15+ setControlVisibility ,
16+ setCounterInfo ,
17+ setServerId ,
18+ setSupported ,
19+ setUserData ,
20+ setUserId
21+ } from './actions' ;
2122import { detect } from 'detect-browser' ;
2223import Unsupport from "./components/Unsupport/Unsupport" ;
2324import jQuery from "jquery" ;
25+ import * as common from './common/common' ;
2426import {
2527 errorHandler ,
26- mergeDeep ,
28+ getCurrentUser ,
29+ getDefaultServerConfig ,
30+ getHttpProtocol ,
2731 getParam ,
28- setAuthHeader ,
2932 getWithCredentials ,
30- getHttpProtocol ,
31- getDefaultServerConfig ,
32- getCurrentUser ,
33- getDefaultServerId
33+ mergeDeep ,
34+ setAuthHeader
3435} from './common/common' ;
3536
3637import Home from "./components/Home/Home" ;
3738import Topology from "./components/Topology/Topology" ;
38- import * as common from "./common/common" ;
3939import Debug from "./components/Debug/Debug" ;
4040import Controller from "./components/Controller/Controller" ;
4141import _ from "lodash" ;
@@ -66,7 +66,7 @@ class App extends Component {
6666 this . props . addRequest ( ) ;
6767
6868 let origin = getHttpProtocol ( config ) ;
69- const conf = common . confBuilder ( getHttpProtocol ( config ) , config , user , getDefaultServerId ( config ) ) ;
69+ const conf = common . confBuilder ( getHttpProtocol ( config ) , config , user , this . getScouterApiServerId ( ) ) ;
7070 ScouterApi . isAuthentification ( conf )
7171 . done ( ( msg ) => {
7272 if ( msg && Number ( msg . status ) === 200 ) {
@@ -118,7 +118,8 @@ class App extends Component {
118118 return server . default ;
119119 } ) ;
120120 if ( JSON . stringify ( currentApiServer ) !== JSON . stringify ( nextApiServer ) ) {
121- this . getCounterModel ( nextProps . config , nextProps . user , true ) ;
121+
122+ this . getCounterModel ( nextProps . config , nextProps . user , true , this . getScouterApiServerId ( ) ) ;
122123 }
123124
124125
@@ -129,10 +130,15 @@ class App extends Component {
129130 let nextUser = nextProps . user [ origin ] ;
130131 let currentUser = this . props . user [ origin ] ;
131132 if ( nextUser && ( JSON . stringify ( currentUser ) !== JSON . stringify ( nextUser ) ) ) {
132- this . getCounterModel ( nextProps . config , nextProps . user , true ) ;
133+ this . getCounterModel ( nextProps . config , nextProps . user , true , nextProps . serverId . server [ 0 ] . id ) ;
133134 }
134135 }
135136 }
137+ if ( this . props . serverId . server ) {
138+ if ( this . props . serverId . server [ 0 ] . id !== nextProps . serverId . server [ 0 ] . id ) {
139+ this . getCounterModel ( nextProps . config , nextProps . user , true , nextProps . serverId . server [ 0 ] . id ) ;
140+ }
141+ }
136142
137143
138144 if ( JSON . stringify ( this . props . objects ) !== JSON . stringify ( nextProps . objects ) || JSON . stringify ( this . props . user ) !== JSON . stringify ( nextProps . user ) || JSON . stringify ( this . props . config ) !== JSON . stringify ( nextProps . config ) ) {
@@ -161,7 +167,9 @@ class App extends Component {
161167 } , seconds * 1000 ) ;
162168 }
163169 } ;
164-
170+ getScouterApiServerId = ( ) => {
171+ return this . props . serverId . server ? this . props . serverId . server [ 0 ] . id : getParam ( this . props , 'activesid' ) ;
172+ } ;
165173 getRealTimeAlert = ( objects ) => {
166174 const that = this ;
167175
@@ -180,7 +188,7 @@ class App extends Component {
180188 jQuery . ajax ( {
181189 method : "GET" ,
182190 async : true ,
183- url : getHttpProtocol ( this . props . config ) + "/scouter/v1/alert/realTime/" + offset1 + "/" + offset2 + "? objType=" + objType ,
191+ url : getHttpProtocol ( this . props . config ) + "/scouter/v1/alert/realTime/" + offset1 + "/" + offset2 + `?serverId= ${ this . getScouterApiServerId ( ) } & objType=` + objType ,
184192 xhrFields : getWithCredentials ( that . props . config ) ,
185193 beforeSend : function ( xhr ) {
186194 setAuthHeader ( xhr , that . props . config , getCurrentUser ( that . props . config , that . props . user ) ) ;
@@ -222,16 +230,19 @@ class App extends Component {
222230 }
223231 } ) ;
224232
225- if ( Notification && this . props . config . alert . notification === "Y" && Notification . permission === "granted" ) {
226- for ( let i = 0 ; i < alert . data . length ; i ++ ) {
227- if ( Number ( alert . data [ i ] . time ) > this . mountTime && ! alert . data [ i ] [ "_notificated" ] ) {
228- alert . data [ i ] [ "_notificated" ] = true ;
229-
230- var options = {
231- body : alert . data [ i ] . objName + "\n" + alert . data [ i ] . message ,
232- icon : notificationIcon
233- } ;
234- new Notification ( "[" + alert . data [ i ] . level + "]" + alert . data [ i ] . title , options ) ;
233+ if ( this . props . config . alert . notification === "Y" ) {
234+ if ( typeof Notification === 'function' && Notification . hasOwnProperty ( 'permission' ) ) {
235+ if ( Notification . permission === "granted" ) {
236+ for ( let i = 0 ; i < alert . data . length ; i ++ ) {
237+ if ( Number ( alert . data [ i ] . time ) > this . mountTime && ! alert . data [ i ] [ "_notificated" ] ) {
238+ alert . data [ i ] [ "_notificated" ] = true ;
239+ const options = {
240+ body : alert . data [ i ] . objName + "\n" + alert . data [ i ] . message ,
241+ icon : notificationIcon
242+ } ;
243+ new Notification ( "[" + alert . data [ i ] . level + "]" + alert . data [ i ] . title , options ) ;
244+ }
245+ }
235246 }
236247 }
237248 }
@@ -249,45 +260,28 @@ class App extends Component {
249260 }
250261 } ;
251262
252- getCounterModel = ( config , user , handleError ) => {
263+ getCounterModel = ( config , user , handleError , serverId ) => {
253264
254- const _conf = common . confBuilder ( getHttpProtocol ( config ) , config , user , getDefaultServerId ( config ) ) ;
255- ScouterApi . getSyncConnectedServer ( _conf )
256- . done ( msg => {
265+ const _conf = common . confBuilder ( getHttpProtocol ( config ) , config , user , serverId ) ;
266+ ScouterApi . getCounterModel ( _conf )
267+ . done ( ( msg ) => {
257268 if ( Number ( msg . status ) === 200 ) {
258- Promise . all ( msg . result . map ( ser => {
259- const _serConfig = common . confBuilder ( getHttpProtocol ( config ) , config , user , ser . id ) ;
260- return ScouterApi . getCounterModel ( _serConfig )
261- } ) )
262- . then ( msg => {
263- const _f = [ ] ;
264- const _o = [ ] ;
265- _ . forEach ( msg , iter => {
266- _f . push ( iter . result . families ) ;
267- _o . push ( iter . result . objTypes ) ;
268-
269- } ) ;
270- //- family info merge
271- const _rf = _ . flatMapDeep ( _f ) ;
272- //- objectType merge
273- const _ro = _ . flatMapDeep ( _o ) ;
274- this . props . setSupported ( true ) ;
275- this . props . setCounterInfo ( _rf , _ro ) ;
276- } ) . catch ( _err => {
277- if ( handleError ) {
278- this . props . setSupported ( false ) ;
279- this . props . pushMessage ( "error" , "Not Supported" , "failed to get matrix information. paper 2.0 is available only on scouter 2.0 and later." ) ;
280- this . props . setControlVisibility ( "Message" , true ) ;
281- }
282- console . error ( _err ) ;
283- } )
284- }
285- } )
286- . fail ( ( xhr , textStatus , errorThrown ) => {
287- if ( handleError ) {
288- errorHandler ( xhr , textStatus , errorThrown , this . props , "getCounterModel" , true ) ;
269+ this . props . setSupported ( true ) ;
270+ if ( msg . result ) {
271+ this . props . setCounterInfo ( msg . result . families , msg . result . objTypes ) ;
272+ }
289273 }
290- } ) ;
274+ } ) . fail ( ( xhr , textStatus , errorThrown ) => {
275+ if ( handleError ) {
276+ if ( xhr . status === 404 ) {
277+ this . props . setSupported ( false ) ;
278+ this . props . pushMessage ( "error" , "Not Supported" , "failed to get matrix information. paper 2.0 is available only on scouter 2.0 and later." ) ;
279+ this . props . setControlVisibility ( "Message" , true ) ;
280+ } else {
281+ errorHandler ( xhr , textStatus , errorThrown , this . props , "getCounterModel" , true ) ;
282+ }
283+ }
284+ } ) ;
291285 } ;
292286
293287 getNotice = ( ) => {
@@ -318,6 +312,7 @@ class App extends Component {
318312 componentWillMount ( ) {
319313 let config = null ;
320314 let str = localStorage . getItem ( "config" ) ;
315+
321316 if ( str ) {
322317 config = JSON . parse ( str ) ;
323318 config = mergeDeep ( this . props . config , config ) ; //for added config's properties on later versions.
@@ -372,8 +367,8 @@ class App extends Component {
372367 config . others . xlogClassicMode = paramXlogClassicMode ;
373368 }
374369
375-
376370 this . props . setConfig ( config ) ;
371+
377372 if ( localStorage ) {
378373 localStorage . setItem ( "config" , JSON . stringify ( config ) ) ;
379374 }
@@ -407,7 +402,7 @@ class App extends Component {
407402 this . setFontSetting ( this . props . config . fontSetting ) ;
408403
409404 // 처음 카운터 모델을 조회하는데, 에러 처리는 하지 않는다
410- this . getCounterModel ( this . props . config , this . props . user , false ) ;
405+ this . getCounterModel ( this . props . config , this . props . user , false , this . getScouterApiServerId ( ) ) ;
411406
412407 // Notice를 조회한다. 이미 조회한 Notice인지 확인하여 하루에 한번만 보여주던지..
413408 // X-Scouter-Notice-Token 응답 헤더는 LocalStorage에 저장하여 다음 요청 헤더로 사용한다.
@@ -534,7 +529,8 @@ let mapStateToProps = (state) => {
534529 user : state . user ,
535530 supported : state . supported ,
536531 objects : state . target . objects ,
537- alert : state . alert
532+ alert : state . alert ,
533+ serverId : state . serverId
538534 } ;
539535} ;
540536
@@ -549,7 +545,8 @@ let mapDispatchToProps = (dispatch) => {
549545 pushMessage : ( category , title , content ) => dispatch ( pushMessage ( category , title , content ) ) ,
550546 setCounterInfo : ( families , objTypes ) => dispatch ( setCounterInfo ( families , objTypes ) ) ,
551547 setSupported : ( supported ) => dispatch ( setSupported ( supported ) ) ,
552- setAlert : ( alert ) => dispatch ( setAlert ( alert ) )
548+ setAlert : ( alert ) => dispatch ( setAlert ( alert ) ) ,
549+ setServerId : ( serverId ) => dispatch ( setServerId ( serverId ) )
553550 } ;
554551} ;
555552
0 commit comments