Skip to content

Commit

Permalink
Merge pull request open-falcon-archive#1 from donh/master
Browse files Browse the repository at this point in the history
[OWL-143] refactor Zabbix API using Beego ORM
  • Loading branch information
hitripod committed Oct 22, 2015
2 parents cc07ac4 + 5e2374e commit 61fdf9c
Show file tree
Hide file tree
Showing 3 changed files with 631 additions and 455 deletions.
21 changes: 18 additions & 3 deletions g/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,25 @@ type GraphConfig struct {
Cluster map[string]string `json:"cluster"`
}

type ApiConfig struct {
Name string `json:"name"`
Token string `json:"token"`
Url string `json:"url"`
}

type DatabaseConfig struct {
Ip string `json:"ip"`
Port string `json:"port"`
Account string `json:"account"`
Password string `json:"password"`
}

type GlobalConfig struct {
Debug string `json:"debug"`
Http *HttpConfig `json:"http"`
Graph *GraphConfig `json:"graph"`
Debug string `json:"debug"`
Http *HttpConfig `json:"http"`
Graph *GraphConfig `json:"graph"`
Api *ApiConfig `json:"api"`
Database *DatabaseConfig `json:"database"`
}

var (
Expand Down
24 changes: 24 additions & 0 deletions http/http.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package http

import (
"github.com/astaxie/beego/orm"
_ "github.com/go-sql-driver/mysql"

"encoding/json"
"log"
"net/http"
Expand All @@ -26,6 +29,27 @@ func Start() {
configGraphRoutes()
configZabbixRoutes()

// start mysql database
account := g.Config().Database.Account
password := g.Config().Database.Password
ip := g.Config().Database.Ip
port := g.Config().Database.Port
database := "graph"
strConn := account + ":" + password + "@tcp(" + ip + ":" + port + ")/" + database + "?charset=utf8"
orm.RegisterDriver("mysql", orm.DR_MySQL)
maxIdle := 30
maxConn := 30
orm.RegisterDataBase("default", "mysql", strConn, maxIdle, maxConn)

database = "falcon_portal"
strConn = account + ":" + password + "@tcp(" + ip + ":" + port + ")/" + database + "?charset=utf8"
orm.RegisterDataBase("falcon_portal", "mysql", strConn, maxIdle, maxConn)
orm.RegisterModel(new(Endpoint))
orm.RegisterModel(new(Grp))
orm.RegisterModel(new(Grp_host))
orm.RegisterModel(new(Grp_tpl))
orm.RegisterModel(new(Tpl))

// start http server
addr := g.Config().Http.Listen
s := &http.Server{
Expand Down
Loading

0 comments on commit 61fdf9c

Please sign in to comment.