Browse Source

Minor changes in templates and function

master
Darshil Chanpura 5 months ago
parent
commit
6e2dc167d8
  1. 4
      .gitignore
  2. 19
      .vscode/launch.json
  3. 10
      templates/email.html
  4. 2
      templates/email.txt
  5. 8
      tracker/email.go
  6. 10
      tracker/init.go

4
.gitignore

@ -1,3 +1,5 @@
/tracker/test.html
.DS_Store
testmains
testmains
release
test.html

19
.vscode/launch.json

@ -0,0 +1,19 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "./cmd/track-instances",
"args": [
"-profile",
"personal"
]
}
]
}

10
templates/email.html

@ -23,19 +23,13 @@
box-sizing: border-box;
}
@media (min-width: 400px) {
.container {
width: 95%;
padding: 0;
}
}
@media (min-width: 550px) {
.container {
width: 80%;
}
.column,
.columns {
@ -48,9 +42,9 @@
}
}
body,
.body {
margin-top: 2rem;
font-weight: 400;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
color: #222;
@ -95,7 +89,7 @@
<body class="body">
<div class="container">
There are {{ .instances | len }} instance(s) which might be running overtime.
There {{ .instances | len | failedinstances }} which might be running overtime.
<table class="table" id="instancesBody">
<thead>
<tr>

2
templates/email.txt

@ -1,4 +1,4 @@
There are {{ .instances | len }} instance(s) which might be running overtime.
There {{ .instances | len | failedinstances }} which might be running overtime.
Details:
{{range .instances}}

8
tracker/email.go

@ -37,6 +37,14 @@ func generateEmail(instances []*awsutils.Instance, templatename, filename string
"gettimediff": func(t time.Time) time.Duration {
return time.Since(t).Truncate(time.Minute)
},
"failedinstances": func(i int) string {
if i > 1 {
return fmt.Sprintf("are %d instances", i)
} else if i == 0 {
return "are no instances"
}
return fmt.Sprintf("is %d instance", i)
},
}).Parse(string(b))
if err != nil {
return "", err

10
tracker/init.go

@ -2,6 +2,9 @@ package tracker
import (
"flag"
"log"
"os"
"path/filepath"
// Static Files packaged in
)
@ -13,7 +16,10 @@ var (
)
func init() {
dir, err := os.UserConfigDir()
if err != nil {
log.Fatal(err)
}
// flag.Var(&checkInterval, "interval", "Interval to check the instances")
flag.StringVar(&configfile, "config", "~/.config/track-instances.yaml", "Config File Path")
flag.StringVar(&configfile, "config", filepath.Join(dir, "track-instances.yaml"), "Config File Path")
}

Loading…
Cancel
Save