Skip to content

Commit

Permalink
UI API refactor, updated all components with the new defined API
Browse files Browse the repository at this point in the history
  • Loading branch information
sbengo committed Jan 25, 2017
1 parent c2c80f3 commit 952c2df
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 98 deletions.
41 changes: 22 additions & 19 deletions pkg/webui/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func WebServer(publicPath string, httpPort int, cfg *config.HTTPConfig, id strin
m.Post("/login", bind(UserLogin{}), myLoginHandler)
m.Post("/logout", myLogoutHandler)

m.Group("/metric", func() {
m.Group("/api/cfg/metric", func() {
m.Get("/", reqSignedIn, GetMetrics)
m.Post("/", reqSignedIn, bind(config.SnmpMetricCfg{}), AddMetric)
m.Put("/:id", reqSignedIn, bind(config.SnmpMetricCfg{}), UpdateMetric)
Expand All @@ -177,7 +177,7 @@ func WebServer(publicPath string, httpPort int, cfg *config.HTTPConfig, id strin
m.Get("/checkondel/:id", reqSignedIn, GetMetricsAffectOnDel)
})

m.Group("/measurement", func() {
m.Group("/api/cfg/measurement", func() {
m.Get("/", reqSignedIn, GetMeas)
m.Get("/type/:type", reqSignedIn, GetMeasByType)
m.Post("/", reqSignedIn, bind(config.MeasurementCfg{}), AddMeas)
Expand All @@ -187,7 +187,7 @@ func WebServer(publicPath string, httpPort int, cfg *config.HTTPConfig, id strin
m.Get("/checkondel/:id", reqSignedIn, GetMeasAffectOnDel)
})

m.Group("/measgroups", func() {
m.Group("/api/cfg/measgroup", func() {
m.Get("/", reqSignedIn, GetMeasGroup)
m.Post("/", reqSignedIn, bind(config.MGroupsCfg{}), AddMeasGroup)
m.Put("/:id", reqSignedIn, bind(config.MGroupsCfg{}), UpdateMeasGroup)
Expand All @@ -196,7 +196,7 @@ func WebServer(publicPath string, httpPort int, cfg *config.HTTPConfig, id strin
m.Get("/checkondel/:id", reqSignedIn, GetMeasGroupsAffectOnDel)
})

m.Group("/measfilters", func() {
m.Group("/api/cfg/measfilters", func() {
m.Get("/", reqSignedIn, GetMeasFilter)
m.Post("/", reqSignedIn, bind(config.MeasFilterCfg{}), AddMeasFilter)
m.Put("/:id", reqSignedIn, bind(config.MeasFilterCfg{}), UpdateMeasFilter)
Expand All @@ -205,7 +205,7 @@ func WebServer(publicPath string, httpPort int, cfg *config.HTTPConfig, id strin
m.Get("/checkondel/:id", reqSignedIn, GetMeasFiltersAffectOnDel)
})

m.Group("/influxservers", func() {
m.Group("/api/cfg/influxservers", func() {
m.Get("/", reqSignedIn, GetInfluxServer)
m.Post("/", reqSignedIn, bind(config.InfluxCfg{}), AddInfluxServer)
m.Put("/:id", reqSignedIn, bind(config.InfluxCfg{}), UpdateInfluxServer)
Expand All @@ -215,7 +215,7 @@ func WebServer(publicPath string, httpPort int, cfg *config.HTTPConfig, id strin
})

// Data sources
m.Group("/snmpdevice", func() {
m.Group("/api/cfg/snmpdevice", func() {
m.Get("/", reqSignedIn, GetSNMPDevices)
m.Post("/", reqSignedIn, bind(config.SnmpDeviceCfg{}), AddSNMPDevice)
m.Put("/:id", reqSignedIn, bind(config.SnmpDeviceCfg{}), UpdateSNMPDevice)
Expand All @@ -224,7 +224,7 @@ func WebServer(publicPath string, httpPort int, cfg *config.HTTPConfig, id strin
m.Get("/checkondel/:id", reqSignedIn, GetSNMPDevicesAffectOnDel)
})

m.Group("/customfilter", func() {
m.Group("/api/cfg/customfilter", func() {
m.Get("/", reqSignedIn, GetCustomFilter)
m.Post("/", reqSignedIn, bind(config.CustomFilterCfg{}), AddCustomFilter)
m.Put("/:id", reqSignedIn, bind(config.CustomFilterCfg{}), UpdateCustomFilter)
Expand All @@ -233,20 +233,23 @@ func WebServer(publicPath string, httpPort int, cfg *config.HTTPConfig, id strin
m.Get("/checkondel/:id", reqSignedIn, GetCustomFiltersAffectOnDel)
})

m.Group("/runtime", func() {
m.Get("/agent/reloadconf/", reqSignedIn, AgentReloadConf)
m.Post("/snmpping/", reqSignedIn, bind(config.SnmpDeviceCfg{}), PingSNMPDevice)
m.Post("/snmpquery/:getmode/:obtype/:data", reqSignedIn, bind(config.SnmpDeviceCfg{}), QuerySNMPDevice)
m.Get("/version/", reqSignedIn, RTGetVersion)
m.Group("/api/rt/agent", func() {
m.Get("/cfg/reload/", reqSignedIn, AgentReloadConf)
m.Post("/snmpconsole/ping/", reqSignedIn, bind(config.SnmpDeviceCfg{}), PingSNMPDevice)
m.Post("/snmpconsole/query/:getmode/:obtype/:data", reqSignedIn, bind(config.SnmpDeviceCfg{}), QuerySNMPDevice)
m.Get("/info/version/", reqSignedIn, RTGetVersion)
})

m.Group("/api/rt/device", func() {
m.Get("/info/", reqSignedIn, RTGetInfo)
m.Get("/info/:id", reqSignedIn, RTGetInfo)
m.Put("/activatedev/:id", reqSignedIn, RTActivateDev)
m.Put("/deactivatedev/:id", reqSignedIn, RTDeactivateDev)
m.Put("/actsnmpdbg/:id", reqSignedIn, RTActSnmpDebugDev)
m.Put("/deactsnmpdbg/:id", reqSignedIn, RTDeactSnmpDebugDev)
m.Put("/setloglevel/:id/:level", reqSignedIn, RTSetLogLevelDev)
m.Get("/getdevicelog/:id", reqSignedIn, RTGetLogFileDev)
m.Get("/forcefltupdate/:id", reqSignedIn, RTForceFltUpdate)
m.Put("/status/activate/:id", reqSignedIn, RTActivateDev)
m.Put("/status/deactivate/:id", reqSignedIn, RTDeactivateDev)
m.Put("/debug/activate/:id", reqSignedIn, RTActSnmpDebugDev)
m.Put("/debug/deactivate/:id", reqSignedIn, RTDeactSnmpDebugDev)
m.Put("/log/setloglevel/:id/:level", reqSignedIn, RTSetLogLevelDev)
m.Get("/log/getdevicelog/:id", reqSignedIn, RTGetLogFileDev)
m.Get("/filter/forcefltupdate/:id", reqSignedIn, RTForceFltUpdate)
})

log.Printf("Server is running on localhost:%d...", port)
Expand Down
31 changes: 1 addition & 30 deletions proxy.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,8 @@
"target": "http://localhost:8090",
"secure": false
},
"/runtime": {
"target": "http://localhost:8090",
"secure": false
},
"/metric": {
"target": "http://localhost:8090",
"secure": false
},
"/measurement": {
"target": "http://localhost:8090",
"secure": false
},
"/measgroups": {
"target": "http://localhost:8090",
"secure": false
},
"/measfilters": {
"target": "http://localhost:8090",
"secure": false
},
"/influxservers": {
"target": "http://localhost:8090",
"secure": false
},
"/snmpdevice": {
"target": "http://localhost:8090",
"secure": false
},
"/customfilter": {
"/api": {
"target": "http://localhost:8090",
"secure": false
}

}
4 changes: 2 additions & 2 deletions src/home/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class Home {
}

reloadConfig() {
this.httpAPI.get('/runtime/agent/reloadconf')
this.httpAPI.get('/api/rt/agent/cfg/reload')
.subscribe(
response => {
alert(response.json())
Expand All @@ -76,7 +76,7 @@ export class Home {

getInfo(filter_s: string) {
// return an observable
return this.httpAPI.get('/runtime/version')
return this.httpAPI.get('/api/rt/agent/info/version/')
.map( (responseData) => {
return responseData.json()});
}
Expand Down
12 changes: 6 additions & 6 deletions src/influxmeas/influxmeascfg.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class InfluxMeasService {
}

addMeas(dev) {
return this.httpAPI.post('/measurement',JSON.stringify(dev,function (key,value) {
return this.httpAPI.post('/api/cfg/measurement',JSON.stringify(dev,function (key,value) {

if ( key == 'IndexAsValue' ) return ( value === "true" || value === true);
return value;
Expand All @@ -23,7 +23,7 @@ export class InfluxMeasService {

editMeas(dev, id) {
console.log("DEV: ",dev);
return this.httpAPI.put('/measurement/'+id,JSON.stringify(dev,function (key,value) {
return this.httpAPI.put('/api/cfg/measurement/'+id,JSON.stringify(dev,function (key,value) {

if ( key == 'IndexAsValue' ) return ( value === "true" || value === true);
return value;
Expand All @@ -34,7 +34,7 @@ export class InfluxMeasService {

getMeas(filter_s: string) {
// return an observable
return this.httpAPI.get('/measurement')
return this.httpAPI.get('/api/cfg/measurement')
.map( (responseData) => {
return responseData.json();
})
Expand Down Expand Up @@ -63,13 +63,13 @@ export class InfluxMeasService {
getMeasById(id : string) {
// return an observable
console.log("ID: ",id);
return this.httpAPI.get('/measurement/'+id)
return this.httpAPI.get('/api/cfg/measurement/'+id)
.map( (responseData) =>
responseData.json()
)};

checkOnDeleteInfluxMeas(id : string){
return this.httpAPI.get('/measurement/checkondel/'+id)
return this.httpAPI.get('/api/cfg/measurement/checkondel/'+id)
.map( (responseData) =>
responseData.json()
).map((deleteobject) => {
Expand All @@ -90,7 +90,7 @@ export class InfluxMeasService {
// return an observable
console.log("ID: ",id);
console.log("DELETING");
return this.httpAPI.delete('/measurement/'+id)
return this.httpAPI.delete('/api/cfg/measurement/'+id)
.map( (responseData) =>
responseData.json()
);
Expand Down
12 changes: 6 additions & 6 deletions src/influxserver/influxservercfg.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class InfluxServerService {
}

addInfluxServer(dev) {
return this.httpAPI.post('/influxservers',JSON.stringify(dev,function (key,value) {
return this.httpAPI.post('/api/cfg/influxservers',JSON.stringify(dev,function (key,value) {
if ( key == 'Port' ) {
return parseInt(value);
}
Expand All @@ -22,7 +22,7 @@ export class InfluxServerService {
}

editInfluxServer(dev, id) {
return this.httpAPI.put('/influxservers/'+id,JSON.stringify(dev,function (key,value) {
return this.httpAPI.put('/api/cfg/influxservers/'+id,JSON.stringify(dev,function (key,value) {
if ( key == 'Port' ) {
return parseInt(value);
}
Expand All @@ -34,7 +34,7 @@ export class InfluxServerService {

getInfluxServer(filter_s: string) {
// return an observable
return this.httpAPI.get('/influxservers')
return this.httpAPI.get('/api/cfg/influxservers')
.map( (responseData) => {
return responseData.json();
})
Expand Down Expand Up @@ -62,13 +62,13 @@ export class InfluxServerService {
getInfluxServerById(id : string) {
// return an observable
console.log("ID: ",id);
return this.httpAPI.get('/influxservers/'+id)
return this.httpAPI.get('/api/cfg/influxservers/'+id)
.map( (responseData) =>
responseData.json()
)};

checkOnDeleteInfluxServer(id : string){
return this.httpAPI.get('/influxservers/checkondel/'+id)
return this.httpAPI.get('/api/cfg/influxservers/checkondel/'+id)
.map( (responseData) =>
responseData.json()
).map((deleteobject) => {
Expand All @@ -89,7 +89,7 @@ export class InfluxServerService {
// return an observable
console.log("ID: ",id);
console.log("DELETING");
return this.httpAPI.delete('/influxservers/'+id)
return this.httpAPI.delete('/api/cfg/influxservers/'+id)
.map( (responseData) =>
responseData.json()
);
Expand Down
12 changes: 6 additions & 6 deletions src/measfilter/measfiltercfg.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class MeasFilterService {
}

addMeasFilter(dev) {
return this.httpAPI.post('/measfilters',JSON.stringify(dev,function (key,value) {
return this.httpAPI.post('/api/cfg/measfilters',JSON.stringify(dev,function (key,value) {
if ( key == 'EnableAlias' ) return ( value === "true" || value === true);
if ( key == 'IDMeasurementCfg') {
if ( value == "" ) return null
Expand All @@ -24,7 +24,7 @@ export class MeasFilterService {

editMeasFilter(dev, id) {
console.log("DEV: ",dev);
return this.httpAPI.put('/measfilters/'+id,JSON.stringify(dev,function (key,value) {
return this.httpAPI.put('/api/cfg/measfilters/'+id,JSON.stringify(dev,function (key,value) {
if ( key == 'EnableAlias' ) return ( value === "true" || value === true);
if ( key == 'IDMeasurementCfg') {
if ( value == "" ) return null
Expand All @@ -37,7 +37,7 @@ export class MeasFilterService {

getMeasFilter(filter_s: string) {
// return an observable
return this.httpAPI.get('/measfilters')
return this.httpAPI.get('/api/cfg/measfilters')
.map( (responseData) => {
return responseData.json();
})
Expand Down Expand Up @@ -65,13 +65,13 @@ export class MeasFilterService {
getMeasFilterById(id : string) {
// return an observable
console.log("ID: ",id);
return this.httpAPI.get('/measfilters/'+id)
return this.httpAPI.get('/api/cfg/measfilters/'+id)
.map( (responseData) =>
responseData.json()
)};

checkOnDeleteMeasFilter(id : string){
return this.httpAPI.get('/measfilters/checkondel/'+id)
return this.httpAPI.get('/api/cfg/measfilters/checkondel/'+id)
.map( (responseData) =>
responseData.json()
).map((deleteobject) => {
Expand All @@ -92,7 +92,7 @@ export class MeasFilterService {
// return an observable
console.log("ID: ",id);
console.log("DELETING");
return this.httpAPI.delete('/measfilters/'+id)
return this.httpAPI.delete('/api/cfg/measfilters/'+id)
.map( (responseData) =>
responseData.json()
);
Expand Down
12 changes: 6 additions & 6 deletions src/measgroup/measgroupcfg.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class MeasGroupService {
}

addMeasGroup(dev) {
return this.httpAPI.post('/measgroups',JSON.stringify(dev,function (key,value) {
return this.httpAPI.post('/api/cfg/measgroup',JSON.stringify(dev,function (key,value) {
return value;
}))
.map( (responseData) => responseData.json());
Expand All @@ -21,15 +21,15 @@ export class MeasGroupService {
editMeasGroup(dev, id) {
console.log("DEV: ",dev);
//TODO: Se tiene que coger el oldid para substituir en la configuración lo que toque!!!!
return this.httpAPI.put('/measgroups/'+id,JSON.stringify(dev,function (key,value) {
return this.httpAPI.put('/api/cfg/measgroup/'+id,JSON.stringify(dev,function (key,value) {
return value;
}))
.map( (responseData) => responseData.json());
}

getMeasGroup(filter_s: string) {
// return an observable
return this.httpAPI.get('/measgroups')
return this.httpAPI.get('/api/cfg/measgroup')
.map( (responseData) => {
return responseData.json();
})
Expand Down Expand Up @@ -57,13 +57,13 @@ export class MeasGroupService {
getMeasGroupById(id : string) {
// return an observable
console.log("ID: ",id);
return this.httpAPI.get('/measgroups/'+id)
return this.httpAPI.get('/api/cfg/measgroup/'+id)
.map( (responseData) =>
responseData.json()
)};

checkOnDeleteMeasGroups(id : string){
return this.httpAPI.get('/measgroups/checkondel/'+id)
return this.httpAPI.get('/api/cfg/measgroup/checkondel/'+id)
.map( (responseData) =>
responseData.json()
).map((deleteobject) => {
Expand All @@ -84,7 +84,7 @@ export class MeasGroupService {
// return an observable
console.log("ID: ",id);
console.log("DELETING");
return this.httpAPI.delete('/measgroups/'+id)
return this.httpAPI.delete('/api/cfg/measgroup/'+id)
.map( (responseData) =>
responseData.json()
);
Expand Down
Loading

0 comments on commit 952c2df

Please sign in to comment.