1+ import jQuery from "jquery" ;
2+ import { getCurrentUser , getWithCredentials , setAuthHeader } from "./common" ;
3+
4+ export default class ScouterApi {
5+ //- Default Api
6+ // App, Control API List
7+ static isAuthentification ( config ) {
8+ const { addr, conf, user, serverId} = config ;
9+
10+ return jQuery . ajax ( {
11+ method : "GET" ,
12+ async : true ,
13+ url : `${ addr } /scouter/v1/kv/a?serverId=${ serverId } ` ,
14+ xhrFields : getWithCredentials ( conf ) ,
15+ beforeSend : ( xhr ) => setAuthHeader ( xhr , conf , user )
16+ } ) ;
17+ }
18+ static getObjectPreset ( config ) {
19+ const { addr, conf, user, serverId} = config ;
20+
21+ return jQuery . ajax ( {
22+ method : "GET" ,
23+ async : true ,
24+ url : `${ addr } /scouter/v1/kv/__scouter_paper_preset?serverId=${ serverId } ` ,
25+ xhrFields : getWithCredentials ( conf ) ,
26+ beforeSend : ( xhr ) => setAuthHeader ( xhr , conf , getCurrentUser ( conf , user ) )
27+ } ) ;
28+ }
29+ static getAlertList ( config , offset , objType ) {
30+ const { addr, conf, user, serverId} = config ;
31+ const { ol, la} = offset ;
32+ return jQuery . ajax ( {
33+ method : "GET" ,
34+ async : true ,
35+ url : `${ addr } /scouter/v1/alert/realTime/${ ol } /${ la } ?objType=${ objType } &serverId=${ serverId } ` ,
36+ xhrFields : getWithCredentials ( conf ) ,
37+ beforeSend : ( xhr ) => setAuthHeader ( xhr , conf , getCurrentUser ( conf , user ) )
38+ } ) ;
39+ }
40+ static getConterModel ( config ) {
41+ const { addr, conf, user, serverId} = config ;
42+ return jQuery . ajax ( {
43+ method : "GET" ,
44+ async : true ,
45+ url : `${ addr } /scouter/v1/info/counter-model?serverId=${ serverId } ` ,
46+ xhrFields : getWithCredentials ( conf ) ,
47+ beforeSend : ( xhr ) => setAuthHeader ( xhr , conf , getCurrentUser ( conf , user ) )
48+ } ) ;
49+ }
50+
51+ static getMonitoringObjects ( config ) {
52+ const { addr, conf, user, serverId} = config ;
53+ return jQuery . ajax ( {
54+ method : "GET" ,
55+ async : true ,
56+ url : `${ addr } scouter/v1/object?serverId=${ serverId } ` ,
57+ xhrFields : getWithCredentials ( conf ) ,
58+ beforeSend : ( xhr ) => setAuthHeader ( xhr , conf , getCurrentUser ( conf , user ) )
59+ } ) ;
60+
61+ }
62+ static getConnectedServer ( config ) {
63+ const { addr, conf, user} = config ;
64+ return jQuery . ajax ( {
65+ method : "GET" ,
66+ async : true ,
67+ url : `${ addr } scouter/v1/info/server` ,
68+ xhrFields : getWithCredentials ( conf ) ,
69+ beforeSend : ( xhr ) => setAuthHeader ( xhr , conf , getCurrentUser ( conf , user ) )
70+ } ) ;
71+
72+ }
73+ //- 실시간 쪽
74+ static getRealTimeCounter ( config , params , objects ) {
75+ const { addr, conf, user, serverId} = config ;
76+ return jQuery . ajax ( {
77+ method : "GET" ,
78+ async : true ,
79+ url : `${ addr } /scouter/v1/counter/realTime/${ params } ?objHashes=${ JSON . stringify ( objects . map ( obj => Number ( obj . objHash ) ) ) } ?serverId=${ serverId } ` ,
80+ xhrFields : getWithCredentials ( conf ) ,
81+ beforeSend : ( xhr ) => setAuthHeader ( xhr , conf , getCurrentUser ( conf , user ) )
82+ } ) ;
83+ }
84+ }
0 commit comments