migrate to new server

This commit is contained in:
Joerg Lehmann 2021-04-10 21:04:02 +02:00
parent 23aa879522
commit f1a6e6df86
6 changed files with 20477 additions and 13 deletions

View File

@ -9,6 +9,7 @@ import (
"io/ioutil"
"log"
"net/http"
"os"
"strconv"
"strings"
"time"
@ -212,7 +213,7 @@ func InsertAlert(prefix string, deveui string, email string, threshold int) {
_, err := conn.Do("SET", prefix+deveui+":"+email, threshold)
if err != nil {
logit("InsertAlert: Error inserting: " + prefix + deveui + ":" + email)
logit("InsertAlert: Error inserting: " + prefix + deveui + ":" + email)
}
}
@ -280,7 +281,10 @@ func getLastMetrics(deveui string) OneMetric {
}
// Set headers
req.Header.Set("Authorization", "Token nKYCoz3TA-LItYXG988DjdiStMhrfKmFXQqzxrjzJJ7Ek_iUttzFSE9lfe3s6q99EMdcrjuGlDAjp4Y0VnNRXw==")
var INFLUX_RO_TOKEN = os.Getenv("INFLUX_RO_TOKEN")
// Set headers
req.Header.Set("Authorization", "Token "+INFLUX_RO_TOKEN)
req.Header.Set("accept", "application/csv")
req.Header.Set("content-type", "application/vnd.flux")
@ -335,7 +339,7 @@ func CheckThreshold(d string, vp int, u2 string, last_metric OneMetric, info_thr
if vp <= alert_threshold {
if AlarmNotAlreadySent("alarm_sent_accu:", d, u2, alert_threshold) {
sendEmailAccu(u2, alias, d, last_metric.BatteryPercent, alert_threshold, "ALARM")
InsertAlert("alarm_sent_accu:", d , u2, alert_threshold)
InsertAlert("alarm_sent_accu:", d, u2, alert_threshold)
}
return false
}

View File

@ -7,6 +7,7 @@ import (
"io/ioutil"
"log"
"net/http"
"os"
"strconv"
"strings"
"time"
@ -29,6 +30,8 @@ type OneMetric struct {
DaysUntilDeactivated int // berechneter Wert
}
var INFLUX_RO_TOKEN = os.Getenv("INFLUX_RO_TOKEN")
// metrics handler
func validProperty(prop string) bool {
@ -115,8 +118,8 @@ func metricsHandler(response http.ResponseWriter, request *http.Request) {
mystart = start[0]
}
url := "http://localhost:8086/api/v2/query?org=beieliorg"
data := []byte(fmt.Sprintf(`from(bucket:"beielibucket") |> range(start: %s, stop: %s) |> filter(fn: (r) => r._measurement == "measurement") |> filter(fn: (r) => r._field == "%s") |> filter(fn: (r) => r.deveui == "%s")`, mystart, mystop, property[0], mydeveui))
url := "http://localhost:8086/api/v2/query?org=minibeieliorg"
data := []byte(fmt.Sprintf(`from(bucket:"minibeielibucket") |> range(start: %s, stop: %s) |> filter(fn: (r) => r._measurement == "measurement") |> filter(fn: (r) => r._field == "%s") |> filter(fn: (r) => r.deveui == "%s")`, mystart, mystop, property[0], mydeveui))
req, err := http.NewRequest("POST", url, bytes.NewBuffer(data))
if err != nil {
@ -124,7 +127,7 @@ func metricsHandler(response http.ResponseWriter, request *http.Request) {
}
// Set headers
req.Header.Set("Authorization", "Token nKYCoz3TA-LItYXG988DjdiStMhrfKmFXQqzxrjzJJ7Ek_iUttzFSE9lfe3s6q99EMdcrjuGlDAjp4Y0VnNRXw==")
req.Header.Set("Authorization", "Token "+INFLUX_RO_TOKEN)
req.Header.Set("accept", "application/csv")
req.Header.Set("content-type", "application/vnd.flux")
@ -196,9 +199,9 @@ func lastmetricsHandler(response http.ResponseWriter, request *http.Request) {
log.Println("Url Param 'deveui' is: " + string(mydeveui))
url := "http://localhost:8086/api/v2/query?org=beieliorg"
//data := []byte(fmt.Sprintf(`from(bucket:"beielibucket") |> range(start:-365d) |> filter(fn: (r) => r.deveui == "%s") |> filter(fn: (r) => r._field == "v" or r._field == "t") |> last() |> yield(name: "last")`,mydeveui))
data := []byte(fmt.Sprintf(`from(bucket:"beielibucket")
url := "http://localhost:8086/api/v2/query?org=minibeieliorg"
//data := []byte(fmt.Sprintf(`from(bucket:"minibeielibucket") |> range(start:-365d) |> filter(fn: (r) => r.deveui == "%s") |> filter(fn: (r) => r._field == "v" or r._field == "t") |> last() |> yield(name: "last")`,mydeveui))
data := []byte(fmt.Sprintf(`from(bucket:"minibeielibucket")
|> range(start:-365d)
|> filter(fn: (r) => r._measurement == "measurement" and r.deveui == "%s")
|> filter(fn: (r) => r._field == "t" or r._field == "h" or r._field == "w" or r._field == "p" or r._field == "vp")
@ -210,7 +213,7 @@ func lastmetricsHandler(response http.ResponseWriter, request *http.Request) {
}
// Set headers
req.Header.Set("Authorization", "Token nKYCoz3TA-LItYXG988DjdiStMhrfKmFXQqzxrjzJJ7Ek_iUttzFSE9lfe3s6q99EMdcrjuGlDAjp4Y0VnNRXw==")
req.Header.Set("Authorization", "Token "+INFLUX_RO_TOKEN)
req.Header.Set("accept", "application/csv")
req.Header.Set("content-type", "application/vnd.flux")
@ -294,8 +297,8 @@ func CalcDaysUntil(mydate string) int {
func getLastMetrics(deveui string) OneMetric {
var res OneMetric
url := "http://localhost:8086/api/v2/query?org=beieliorg"
data := []byte(fmt.Sprintf(`from(bucket:"beielibucket")
url := "http://localhost:8086/api/v2/query?org=minibeieliorg"
data := []byte(fmt.Sprintf(`from(bucket:"minibeielibucket")
|> range(start:-365d)
|> filter(fn: (r) => r._measurement == "measurement" and r.deveui == "%s")
|> filter(fn: (r) => r._field == "t" or r._field == "h" or r._field == "w" or r._field == "p" or r._field == "vp")
@ -308,7 +311,7 @@ func getLastMetrics(deveui string) OneMetric {
}
// Set headers
req.Header.Set("Authorization", "Token nKYCoz3TA-LItYXG988DjdiStMhrfKmFXQqzxrjzJJ7Ek_iUttzFSE9lfe3s6q99EMdcrjuGlDAjp4Y0VnNRXw==")
req.Header.Set("Authorization", "Token "+INFLUX_RO_TOKEN)
req.Header.Set("accept", "application/csv")
req.Header.Set("content-type", "application/vnd.flux")

17
static/502.html Normal file
View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>mini-beieli.ch - die besondere Bienenstockwaage</title>
<link rel="stylesheet" href="/mini-beieli-web.css">
<link rel="stylesheet" href="/mini-beieli-web-custom.css">
</head>
<body>
<div class="section px-4 py-4">
<div class="notification is-danger">
<strong>Oops, da ist was schiefgegangen!</strong>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,84 @@
.image.is-10by1 img, .image.is-20by3 img {
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
height: 100%;
width: 100%;
}
.image.is-10by1 {
padding-top: 10%;
}
.image.is-20by3 {
padding-top: 15%;
}
hr {
margin: 0 0 15px 0;
}
.signup-box {
margin: auto;
width: 300px;
background: rgba(255,255,255,0.05);
border: 1px solid rgba(255,255,255,0.3);
border-radius: 10px;
}
.block-link {
text-decoration: none !important;
}
.apexcharts-title-text {
font-weight: 700 !important;
font-size: 24px !important;
font-family: "Rubik", sans-serif !important;
}
.apexcharts-legend {
font-family: "Rubik", sans-serif;
}
/**
* * The CSS shown here will not be introduced in the Quickstart guide, but
* * shows how you can use CSS to style your Element's container.
* */
input,
.StripeElement {
height: 40px;
padding: 10px 12px;
color: #32325d;
background-color: white;
border: 1px solid transparent;
border-radius: 4px;
box-shadow: 0 1px 3px 0 #e6ebf1;
-webkit-transition: box-shadow 150ms ease;
transition: box-shadow 150ms ease;
}
input:focus,
.StripeElement--focus {
box-shadow: 0 1px 3px 0 #cfd7df;
}
.StripeElement--invalid {
border-color: #fa755a;
}
.StripeElement--webkit-autofill {
background-color: #fefde5 !important;
}
.checkboxes input {
vertical-align: middle;
}
.checkboxes label span {
vertical-align: middle;
margin-left: 5px;
}

20353
static/mini-beieli-web.css Normal file

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,9 @@ After=syslog.target
After=network.target
[Service]
Environment="INFLUX_RO_TOKEN=xxx"
Environment="STRIPE_KEY=sk_xxx"
Environment="STRIPE_PK=pk_xxx"
Type=simple
User=beieli
Group=beieli