Skip to content

Commit 614edad

Browse files
committed
Updated Home page
1 parent 650ae04 commit 614edad

File tree

6 files changed

+44
-38
lines changed

6 files changed

+44
-38
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/gin-gonic/gin v1.6.3
99
github.com/go-co-op/gocron v0.3.1
1010
github.com/jinzhu/now v1.1.1
11+
github.com/labstack/gommon v0.3.0
1112
github.com/pelletier/go-toml v1.8.1 // indirect
1213
github.com/sirupsen/logrus v1.4.2
1314
github.com/spf13/viper v1.7.0

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
206206
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
207207
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
208208
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
209+
github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0=
210+
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
209211
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
210212
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
211213
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
@@ -319,6 +321,10 @@ github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
319321
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
320322
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
321323
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
324+
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
325+
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
326+
github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8=
327+
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
322328
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
323329
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
324330
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=

provider/aws/aws.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,12 @@ func NewProvider() (*types.Provider, error) {
6262

6363
ec2Manager := newEC2Manager(cfg, logFile)
6464
s3Manager := newS3Manager(cfg, logFile)
65-
fmt.Println("Managers: ", s3Manager, ec2Manager)
6665

6766
resourceManagers = map[string]*types.ResourceManager{
6867
ec2Manager.Name: &ec2Manager,
6968
s3Manager.Name: &s3Manager,
7069
}
7170

72-
fmt.Println(resourceManagers)
73-
7471
aws.ResourceManagers = resourceManagers
7572
return &aws, nil
7673
}

web/controllers/home.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,33 @@ import (
44
"net/http"
55

66
"github.com/gin-gonic/gin"
7+
"github.com/labstack/gommon/log"
8+
9+
"github.com/mensaah/reka/types"
10+
"github.com/mensaah/reka/web/models"
711
)
812

913
//HomeGet handles GET / route
1014
func HomeGet(c *gin.Context) {
15+
var r types.Resource
16+
17+
db := models.GetDB()
1118
h := DefaultH(c)
19+
// TODO Specify Provider to query from
20+
// provider := strings.ToLower(c.Param("provider")) || config.GetProviders()[0]
21+
// Filter where resource Manager is for a particular provider
22+
23+
h["TrackedResourceCount"] = db.Not("state = ?", types.Destroyed).Find(&r).RowsAffected
24+
h["RunningResourceCount"] = db.Where("state = ?", types.Running).Find(&r).RowsAffected
25+
h["StoppedResourceCount"] = db.Where("state = ?", types.Stopped).Find(&r).RowsAffected
26+
h["DestroyedResourceCount"] = db.Where("state = ?", types.Destroyed).Find(&r).RowsAffected
27+
28+
// Get Recent Resource Updates
29+
var recentResourceUpdates []types.Resource
30+
if err := db.Order("updated_at desc").Limit(10).Find(&recentResourceUpdates); err != nil {
31+
log.Error("DB Error: ", err.Error)
32+
}
33+
h["RecentResourceUpdates"] = recentResourceUpdates
34+
1235
c.HTML(http.StatusOK, "index", h)
1336
}

web/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func main() {
6060
// router.Use(controllers.ContextData())
6161

6262
router.GET("/", controllers.HomeGet)
63+
router.GET("/provider/:provider", controllers.HomeGet)
6364
// router.NoRoute(controllers.NotFound)
6465
// router.NoMethod(controllers.MethodNotAllowed)
6566

web/templates/index.tmpl

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<!-- small box -->
2323
<div class="small-box bg-info">
2424
<div class="inner">
25-
<h3>150</h3>
25+
<h3>{{ .TrackedResourceCount }}</h3>
2626

2727
<p>Tracked Resource</p>
2828
</div>
@@ -37,7 +37,7 @@
3737
<!-- small box -->
3838
<div class="small-box bg-success">
3939
<div class="inner">
40-
<h3>53</h3>
40+
<h3>{{ .RunningResourceCount }}</h3>
4141

4242
<p>Running Resources</p>
4343
</div>
@@ -52,7 +52,7 @@
5252
<!-- small box -->
5353
<div class="small-box bg-warning">
5454
<div class="inner">
55-
<h3>44</h3>
55+
<h3>{{ .StoppedResourceCount }}</h3>
5656

5757
<p>Stopped Resources</p>
5858
</div>
@@ -67,7 +67,7 @@
6767
<!-- small box -->
6868
<div class="small-box bg-danger">
6969
<div class="inner">
70-
<h3>65</h3>
70+
<h3>{{ .DestroyedResourceCount }}</h3>
7171

7272
<p>Destroyed Resources</p>
7373
</div>
@@ -101,48 +101,26 @@
101101
<thead>
102102
<tr>
103103
<th>Resource ID</th>
104+
<th>Region</th>
104105
<th>Resource Type</th>
105106
<th>Status</th>
106107
<th>Time status changed</th>
107108
</tr>
108109
</thead>
109110
<tbody>
111+
112+
{{range .RecentResourceUpdates}}
110113
<tr>
111-
<td><a href="pages/examples/invoice.html">OR9842</a></td>
112-
<td>EC2</td>
113-
<td><span class="badge badge-success">Running</span></td>
114+
<td><a href="pages/examples/invoice.html">{{ .UUID }}</a></td>
115+
<td>{{ .Region }}</td>
116+
<td>{{ .ManagerName }}</td>
117+
<td><span class="badge badge-success">{{ .State }}</span></td>
114118
<td>
115119
<div class="sparkbar" data-color="#00a65a" data-height="20">
116-
10/10/2020 8:49:12</div>
117-
</td>
118-
</tr>
119-
<tr>
120-
<td><a href="pages/examples/invoice.html">OR1848</a></td>
121-
<td>EBS</td>
122-
<td><span class="badge badge-warning">Pending</span></td>
123-
<td>
124-
<div class="sparkbar" data-color="#f39c12" data-height="20">
125-
10/10/2020 8:57:12<div>
126-
</td>
127-
</tr>
128-
<tr>
129-
<td><a href="pages/examples/invoice.html">OR7429</a></td>
130-
<td>EC2</td>
131-
<td><span class="badge badge-danger">Stopped</span></td>
132-
<td>
133-
<div class="sparkbar" data-color="#f56954" data-height="20">
134-
10/10/2020 10:08:18</div>
135-
</td>
136-
</tr>
137-
<tr>
138-
<td><a href="pages/examples/invoice.html">OR7429</a></td>
139-
<td>EKS</td>
140-
<td><span class="badge badge-info">Starting</span></td>
141-
<td>
142-
<div class="sparkbar" data-color="#00c0ef" data-height="20">
143-
10/10/2020 15:10:18</div>
120+
{{ .UpdatedAt.Format "Jan 02, 2006 15:04:05 UTC" }}</div>
144121
</td>
145122
</tr>
123+
{{end}}
146124
</tbody>
147125
</table>
148126
</div>

0 commit comments

Comments
 (0)