Skip to content
Permalink
Browse files

Logrus migration. Need to rework on this project though.

  • Loading branch information...
Depado committed Mar 6, 2018
1 parent af6704d commit 9723585376e495b0e30576b59d00119dc7668577
Showing with 18 additions and 21 deletions.
  1. +2 −2 README.md
  2. +4 −0 main.go
  3. +11 −18 models/service.go
  4. +1 −1 templates/index.tmpl
@@ -4,12 +4,12 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/Depado/gomonit)](https://goreportcard.com/report/github.com/Depado/gomonit)
[![Build Status](https://drone.depado.eu/api/badges/Depado/gomonit/status.svg)](https://drone.depado.eu/Depado/gomonit)
[![codecov](https://codecov.io/gh/Depado/gomonit/branch/master/graph/badge.svg)](https://codecov.io/gh/Depado/gomonit)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Depado/bfchroma/blob/master/LICENSE)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Depado/gomonit/blob/master/LICENSE)

Small soft to check if your services are running, providing a web interface.

It also integrates with Github to fetch your commits, and with drone to fetch
the build list. Other versionning system and CI system will eventually be
the build list. Other versioning system and CI system will eventually be
supported in the future.

## Status and Goals
@@ -56,6 +56,10 @@ func main() {

// Set router
r := SetupRouter()
logrus.WithFields(logrus.Fields{
"port": conf.C.Server.Port,
"host": conf.C.Server.Host,
}).Info("Starting server")
if err = r.Run(fmt.Sprintf("%s:%d", conf.C.Server.Host, conf.C.Server.Port)); err != nil {
logrus.WithError(err).Fatal("Couldn't start server")
}
@@ -175,59 +175,59 @@ func (s *Service) FetchBuilds() {

// FetchCommits fetches the last commits associated to the repository
func (s *Service) FetchCommits() {
clog := logrus.WithFields(logrus.Fields{"action": "commits", "service": s.Name})
u := strings.Split(s.Repo.URL, "/")
url := fmt.Sprintf("https://api.github.com/repos/%s/%s/commits", u[len(u)-2], u[len(u)-1])
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Printf("[%s][ERROR][COMMITS] Couldn't create request : %v\n", s.Name, err)
clog.WithError(err).Error("Couldn't create request")
return
}
if conf.C.GithubOAuthToken != "" {
req.Header.Add("Authorization", "token "+conf.C.GithubOAuthToken)
}
res, err := client.Do(req)
if err != nil {
log.Printf("[%s][ERROR][COMMITS] While requesting : %v\n", s.Name, err)
clog.WithError(err).Warn("Couldn't perform request")
return
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
logrus.WithFields(logrus.Fields{
"service": s.Name,
"code": res.StatusCode,
"message": res.Status,
}).Warn("Couldn't retrieve commits")
clog.WithField("code", res.StatusCode).Warn("Couldn't retrieve commits")
return
}
var all Commits
if err = json.NewDecoder(res.Body).Decode(&all); err != nil {
log.Printf("[%s][ERROR][COMMITS] Couldn't decode response : %v\n", s.Name, err)
clog.WithError(err).Error("Couldn't decode response")
return
}
s.LastCommits = all
}

// FetchRepoInfos fetches the repository information
func (s *Service) FetchRepoInfos() {
clog := logrus.WithFields(logrus.Fields{"action": "repo", "service": s.Name})
u := strings.Split(s.Repo.URL, "/")
url := fmt.Sprintf("https://api.github.com/repos/%s/%s", u[len(u)-2], u[len(u)-1])
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Printf("[%s][ERROR][REPO] Couldn't create request : %v\n", s.Name, err)
clog.WithError(err).Error("Couldn't create request")
return
}
if conf.C.GithubOAuthToken != "" {
req.Header.Add("Authorization", "token "+conf.C.GithubOAuthToken)
}
res, err := client.Do(req)
if err != nil {
log.Printf("[%s][ERROR][REPO] While requesting : %v\n", s.Name, err)
clog.WithError(err).Error("Couldn't perform request")
return
}
defer res.Body.Close()
var repo GHRepo
if err = json.NewDecoder(res.Body).Decode(&repo); err != nil {
log.Printf("[%s][ERROR][REPO] Couldn't decode response : %v\n", s.Name, err)
clog.WithError(err).Error("Couldn't decode response")
return
}
s.Repo.Stars = repo.StargazersCount
@@ -268,10 +268,3 @@ func (ss Services) Monitor() {
}
}(ss)
}

// ServiceForm is the struct representing a Service (to add, or modify)
type ServiceForm struct {
Name string `form:"name" binding:"required"`
URL string `form:"url" binding:"required"`
ShortURL string `form:"shorturl" binding:"required"`
}
@@ -101,7 +101,7 @@
<div class="ui card {{ if eq .Status 200 }}green{{ else if eq .URL "" }}green{{ else }}red{{ end }}">
<div class="content">
<img class="right floated mini ui image" {{ if .Icon }}src="{{ .Icon }}" alt="{{ .Name }}" {{ end }}>
<div class="header"><a href="#" class="tooltip-down" style="color: rgba(0,0,0,.85);" id="history-{{ $index }}" data-content="View History" data-variation="tiny">{{ .Name }}</a></div>
<div class="header">{{ .Name }}</div>
<div class="meta">
<a href="{{ .URL }}">{{ if eq .ShortURL "" }}-{{ else }}{{ .ShortURL }}{{ end }}</a>
</div>

0 comments on commit 9723585

Please sign in to comment.
You can’t perform that action at this time.