Merge pull request #2 from benjaminbear/improve-error-logging

Improve error logging
This commit is contained in:
benjaminbear 2020-04-29 10:54:26 +02:00 committed by GitHub
commit d84bcbeef6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 26 additions and 24 deletions

View File

@ -205,6 +205,7 @@ func (h *Handler) UpdateIP(c echo.Context) (err error) {
if log.CallerIP == "" {
log.CallerIP, _, err = net.SplitHostPort(c.Request().RemoteAddr)
if err != nil {
log.Message = "Bad Request: Unable to get caller IP"
if err = h.CreateLogEntry(log); err != nil {
fmt.Println(err)
}
@ -216,6 +217,7 @@ func (h *Handler) UpdateIP(c echo.Context) (err error) {
// Validate hostname
hostname := c.QueryParam("hostname")
if hostname == "" || hostname != h.AuthHost.Hostname+"."+h.AuthHost.Domain {
log.Message = "Hostname or combination of authenticated user and hostname is invalid"
if err = h.CreateLogEntry(log); err != nil {
fmt.Println(err)
}
@ -229,6 +231,7 @@ func (h *Handler) UpdateIP(c echo.Context) (err error) {
log.SentIP = log.CallerIP
ipType = getIPType(log.SentIP)
if ipType == "" {
log.Message = "Bad Request: Sent IP is invalid"
if err = h.CreateLogEntry(log); err != nil {
fmt.Println(err)
}
@ -239,6 +242,7 @@ func (h *Handler) UpdateIP(c echo.Context) (err error) {
// add/update DNS record
if err = h.updateRecord(log.Host.Hostname, log.SentIP, ipType, log.Host.Domain, log.Host.Ttl); err != nil {
log.Message = fmt.Sprintf("DNS error: %v", err)
if err = h.CreateLogEntry(log); err != nil {
fmt.Println(err)
}
@ -249,6 +253,7 @@ func (h *Handler) UpdateIP(c echo.Context) (err error) {
log.Host.Ip = log.SentIP
log.Host.LastUpdate = log.TimeStamp
log.Status = true
log.Message = "No errors occurred"
if err = h.CreateLogEntry(log); err != nil {
fmt.Println(err)
}

View File

@ -27,7 +27,6 @@ func (h *Handler) ShowLogs(c echo.Context) (err error) {
return c.Render(http.StatusOK, "listlogs", echo.Map{
"logs": logs,
"config": h.Config,
})
}

View File

@ -9,6 +9,7 @@ import (
type Log struct {
gorm.Model
Status bool
Message string
Host Host
HostID uint
SentIP string

File diff suppressed because one or more lines are too long

View File

@ -114,3 +114,12 @@ $("button.generateHash").click(function () {
let input = document.getElementById(id);
input.value = randomHash();
});
$(document).ready(function(){
$(".errorTooltip").tooltip({
track: true,
content: function () {
return $(this).prop('title');
}
});
});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -10,7 +10,10 @@
<title>TheBBCloud DynDNS</title>
<!-- Bootstrap core CSS -->
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<!-- JQueryUI base CSS -->
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.min.css" integrity="sha256-sEGfrwMkIjbgTBwGLVK38BG/XwIiNC/EAG9Rzsfda6A=" crossorigin="anonymous" />
<!-- Custom styles for this template -->
<link href="/static/css/narrow-jumbotron.css" rel="stylesheet">
@ -50,9 +53,10 @@
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="/static/js/ie10-viewport-bug-workaround.js"></script>
<script src="/static/js/jquery-3.4.1.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
<script src="/static/js/actions.js"></script>
</body>
</html>

View File

@ -14,7 +14,7 @@
</thead>
<tbody>
{{range .logs}}
<tr>
<tr class="errorTooltip" title="<b>{{if .Status}}Successful{{else}}Failed{{end}}</b><br>{{.Message}}">
<td class="align-middle mx-auto"><div class="{{if .Status}}bg-success{{else}}bg-danger{{end}}" style="width: 16px; height: 16px; margin: auto"></div></td>
<td>{{.Host.Hostname}}.{{.Host.Domain}}</td>
<td>{{.SentIP}}</td>