basic config validation added
This commit is contained in:
parent
e7aa9691bc
commit
a148f4250d
|
@ -1,10 +1,55 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
/*
|
import (
|
||||||
TODO validation
|
"fmt"
|
||||||
- title uniquness and mandatory within a single type of widget
|
"github.com/sqshq/sampler/console"
|
||||||
- label uniqueness and mandatory (if > 1 data bullets)
|
)
|
||||||
*/
|
|
||||||
func (c *Config) validate() {
|
func (c *Config) validate() {
|
||||||
|
|
||||||
|
var components []ComponentConfig
|
||||||
|
|
||||||
|
for _, c := range c.RunCharts {
|
||||||
|
components = append(components, c.ComponentConfig)
|
||||||
|
validateLabelsUniqueness(c.Title, c.Items)
|
||||||
|
}
|
||||||
|
for _, c := range c.BarCharts {
|
||||||
|
components = append(components, c.ComponentConfig)
|
||||||
|
validateLabelsUniqueness(c.Title, c.Items)
|
||||||
|
}
|
||||||
|
for _, c := range c.SparkLines {
|
||||||
|
components = append(components, c.ComponentConfig)
|
||||||
|
}
|
||||||
|
for _, c := range c.Gauges {
|
||||||
|
components = append(components, c.ComponentConfig)
|
||||||
|
}
|
||||||
|
for _, c := range c.AsciiBoxes {
|
||||||
|
components = append(components, c.ComponentConfig)
|
||||||
|
}
|
||||||
|
for _, c := range c.TextBoxes {
|
||||||
|
components = append(components, c.ComponentConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
validateTitlesUniqueness(components)
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateLabelsUniqueness(title string, items []Item) {
|
||||||
|
labels := make(map[string]bool)
|
||||||
|
for _, c := range items {
|
||||||
|
label := *c.Label
|
||||||
|
if _, contains := labels[label]; contains {
|
||||||
|
console.Exit(fmt.Sprintf("Config validation error: item labels should be unique. Please rename '%s' in '%s'", label, title))
|
||||||
|
}
|
||||||
|
labels[label] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateTitlesUniqueness(components []ComponentConfig) {
|
||||||
|
titles := make(map[string]bool)
|
||||||
|
for _, c := range components {
|
||||||
|
if _, contains := titles[c.Title]; contains {
|
||||||
|
console.Exit(fmt.Sprintf("Config validation error: component titles should be unique. Please rename '%s'", c.Title))
|
||||||
|
}
|
||||||
|
titles[c.Title] = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
239
example.yml
239
example.yml
|
@ -1,127 +1,128 @@
|
||||||
variables:
|
variables:
|
||||||
mongoconnection: mongo --quiet --host=localhost blog
|
mongoconnection: mongo --quiet --host=localhost blog
|
||||||
runcharts:
|
runcharts:
|
||||||
- title: SEARCH ENGINE RESPONSE TIME (sec)
|
- title: SEARCH ENGINE RESPONSE TIME (sec)
|
||||||
position: [[0, 0], [52, 16]]
|
position: [[0, 0], [52, 16]]
|
||||||
triggers:
|
triggers:
|
||||||
- title: Latency threshold exceeded
|
- title: Latency threshold exceeded
|
||||||
condition: echo "$prev < 0.8 && $cur > 0.8" |bc -l
|
condition: echo "$prev < 0.8 && $cur > 0.8" |bc -l
|
||||||
actions:
|
actions:
|
||||||
terminal-bell: true
|
terminal-bell: true
|
||||||
sound: true
|
sound: true
|
||||||
visual: true
|
visual: true
|
||||||
script: 'say alert: ${label} latency exceeded ${cur} second'
|
script: 'say alert: ${label} latency exceeded ${cur} second'
|
||||||
scale: 3
|
scale: 3
|
||||||
items:
|
items:
|
||||||
- label: GOOGLE
|
- label: GOOGLE
|
||||||
sample: curl -o /dev/null -s -w '%{time_total}' https://www.google.com
|
sample: curl -o /dev/null -s -w '%{time_total}' https://www.google.com
|
||||||
- label: YAHOO
|
- label: YAHOO
|
||||||
sample: curl -o /dev/null -s -w '%{time_total}' https://search.yahoo.com
|
sample: curl -o /dev/null -s -w '%{time_total}' https://search.yahoo.com
|
||||||
- label: BING
|
- label: BING
|
||||||
sample: curl -o /dev/null -s -w '%{time_total}' https://www.bing.com
|
sample: curl -o /dev/null -s -w '%{time_total}' https://www.bing.com
|
||||||
- title: MONGO COLLECTIONS COUNT
|
- title: MONGO COLLECTIONS COUNT
|
||||||
position: [[53, 0], [27, 8]]
|
position: [[53, 0], [27, 8]]
|
||||||
legend:
|
legend:
|
||||||
enabled: true
|
enabled: true
|
||||||
details: false
|
details: false
|
||||||
scale: 0
|
scale: 0
|
||||||
items:
|
items:
|
||||||
- label: ACTIVE
|
- label: ACTIVE
|
||||||
init: $mongoconnection
|
init: $mongoconnection
|
||||||
sample: db.getCollection('posts').find({status:'ACTIVE'}).itcount()
|
sample: db.getCollection('posts').find({status:'ACTIVE'}).itcount()
|
||||||
- label: INACTIVE
|
- label: INACTIVE
|
||||||
init: $mongoconnection
|
init: $mongoconnection
|
||||||
sample: db.getCollection('posts').find({status:'INACTIVE'}).itcount()
|
sample: db.getCollection('posts').find({status:'INACTIVE'}).itcount()
|
||||||
barcharts:
|
barcharts:
|
||||||
- title: EVENTS BY STATUS
|
- title: EVENTS BY STATUS
|
||||||
position: [[0, 17], [28, 12]]
|
position: [[0, 17], [28, 12]]
|
||||||
rate-ms: 300
|
rate-ms: 300
|
||||||
scale: 0
|
scale: 0
|
||||||
items:
|
items:
|
||||||
- label: NEW
|
- label: NEW
|
||||||
init: $mongoconnection
|
init: $mongoconnection
|
||||||
sample: db.getCollection('posts').find({status:'ACTIVE'}).itcount()
|
sample: db.getCollection('posts').find({status:'ACTIVE'}).itcount()
|
||||||
- label: TRIGGERED
|
- label: TRIGGERED
|
||||||
init: $mongoconnection
|
init: $mongoconnection
|
||||||
sample: db.getCollection('posts').find({status:'INACTIVE'}).itcount()
|
sample: db.getCollection('posts').find({status:'INACTIVE'}).itcount()
|
||||||
- label: IN_PROCESS
|
- label: IN_PROCESS
|
||||||
init: $mongoconnection
|
init: $mongoconnection
|
||||||
sample: db.getCollection('posts').find({status:'UNKNOWN'}).itcount()
|
sample: db.getCollection('posts').find({status:'UNKNOWN'}).itcount()
|
||||||
- label: FAILED
|
- label: FAILED
|
||||||
init: $mongoconnection
|
init: $mongoconnection
|
||||||
sample: db.getCollection('posts').find({status:'ACTIVE'}).itcount()
|
sample: db.getCollection('posts').find({status:'ACTIVE'}).itcount()
|
||||||
- label: FINISHED
|
- label: FINISHED
|
||||||
init: $mongoconnection
|
init: $mongoconnection
|
||||||
sample: db.getCollection('posts').find({status:'INACTIVE'}).itcount()
|
sample: db.getCollection('posts').find({status:'INACTIVE'}).itcount()
|
||||||
gauges:
|
gauges:
|
||||||
- title: YEAR PROGRESS
|
- title: YEAR PROGRESS
|
||||||
position: [[53, 8], [27, 2]]
|
position: [[53, 8], [27, 2]]
|
||||||
cur:
|
cur:
|
||||||
sample: date +%j
|
sample: date +%j
|
||||||
max:
|
max:
|
||||||
sample: echo 365
|
sample: echo 365
|
||||||
min:
|
min:
|
||||||
sample: echo 0
|
sample: echo 0
|
||||||
- title: DAY PROGRESS
|
- title: DAY PROGRESS
|
||||||
position: [[53, 10], [27, 2]]
|
position: [[53, 10], [27, 2]]
|
||||||
cur:
|
cur:
|
||||||
sample: date +%H
|
sample: date +%H
|
||||||
max:
|
max:
|
||||||
sample: echo 24
|
sample: echo 24
|
||||||
min:
|
min:
|
||||||
sample: echo 0
|
sample: echo 0
|
||||||
- title: HOUR PROGRESS
|
- title: HOUR PROGRESS
|
||||||
position: [[53, 12], [27, 2]]
|
position: [[53, 12], [27, 2]]
|
||||||
cur:
|
cur:
|
||||||
sample: date +%M
|
sample: date +%M
|
||||||
max:
|
max:
|
||||||
sample: echo 60
|
sample: echo 60
|
||||||
min:
|
min:
|
||||||
sample: echo 0
|
sample: echo 0
|
||||||
- title: MINUTE PROGRESS
|
- title: MINUTE PROGRESS
|
||||||
position: [[53, 14], [27, 2]]
|
position: [[53, 14], [27, 2]]
|
||||||
triggers:
|
triggers:
|
||||||
- title: CLOCK BELL EVERY MINUTE
|
- title: CLOCK BELL EVERY MINUTE
|
||||||
condition: '[ $label == "cur" ] && [ $cur -eq 0 ] && echo 1 || echo 0'
|
condition: '[ $label == "cur" ] && [ $cur -eq 0 ] && echo 1 || echo 0'
|
||||||
actions:
|
actions:
|
||||||
sound: true
|
sound: true
|
||||||
script: say -v samantha `date +%I:%M%p`
|
script: say -v samantha `date +%I:%M%p`
|
||||||
cur:
|
cur:
|
||||||
sample: date +%S
|
sample: date +%S
|
||||||
max:
|
max:
|
||||||
sample: echo 60
|
sample: echo 60
|
||||||
min:
|
min:
|
||||||
sample: echo 0
|
sample: echo 0
|
||||||
sparklines:
|
sparklines:
|
||||||
- title: CPU usage
|
- title: CPU usage
|
||||||
position: [[28, 22], [24, 7]]
|
position: [[28, 22], [24, 7]]
|
||||||
scale: 0
|
scale: 0
|
||||||
sample: ps -A -o %cpu | awk '{s+=$1} END {print s}'
|
sample: ps -A -o %cpu | awk '{s+=$1} END {print s}'
|
||||||
- title: Memory pages free
|
- title: Memory pages free
|
||||||
position: [[28, 17], [24, 5]]
|
position: [[28, 17], [24, 5]]
|
||||||
scale: 0
|
scale: 0
|
||||||
sample: memory_pressure | grep 'Pages free' | awk '{print $3}'
|
sample: memory_pressure | grep 'Pages free' | awk '{print $3}'
|
||||||
textboxes:
|
textboxes:
|
||||||
- title: Local weather
|
- title: Local weather
|
||||||
position: [[0, 30], [13, 7]]
|
position: [[0, 30], [13, 7]]
|
||||||
rate-ms: 10000
|
rate-ms: 10000
|
||||||
sample: curl wttr.in?0ATQF
|
sample: curl wttr.in?0ATQF
|
||||||
border: false
|
border: false
|
||||||
- title: New York weather
|
- title: New York weather
|
||||||
position: [[8, 30], [13, 7]]
|
position: [[8, 30], [13, 7]]
|
||||||
rate-ms: 10000
|
rate-ms: 10000
|
||||||
sample: curl wttr.in/newyork?0ATQF
|
sample: curl wttr.in/newyork?0ATQF
|
||||||
border: false
|
border: false
|
||||||
- title: San Francisco weather
|
transform: echo 1
|
||||||
position: [[17, 30], [13, 7]]
|
- title: San Francisco weather
|
||||||
rate-ms: 10000
|
position: [[17, 30], [13, 7]]
|
||||||
sample: curl wttr.in/sanfrancisco?0ATQF
|
rate-ms: 10000
|
||||||
border: false
|
sample: curl wttr.in/sanfrancisco?0ATQF
|
||||||
|
border: false
|
||||||
asciiboxes:
|
asciiboxes:
|
||||||
- title: LOCAL TIME
|
- title: LOCAL TIME
|
||||||
position: [[53, 17], [27, 5]]
|
position: [[53, 17], [27, 5]]
|
||||||
sample: date +%r
|
sample: date +%r
|
||||||
- title: UTC TIME
|
- title: UTC TIME
|
||||||
position: [[53, 22], [27, 7]]
|
position: [[53, 22], [27, 7]]
|
||||||
sample: env TZ=UTC date +%r
|
sample: env TZ=UTC date +%r
|
||||||
font: 3d
|
font: 3d
|
||||||
|
|
Loading…
Reference in New Issue