monwork - bytes.Fields works well enough
This function existed to group fields together, but it had an issue and grouped them wrongly. This caused issues later in the check stage.
This commit is contained in:
parent
82e582f022
commit
ff79584084
@ -167,7 +167,7 @@ func startConfigGen(db *sql.DB, checkInterval time.Duration) {
|
|||||||
time.Sleep(checkInterval)
|
time.Sleep(checkInterval)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, err := tx.Exec(SQLRefreshActiveCheck, check_id, pq.Array(stringToShellFields(cmd.Bytes()))); err != nil {
|
if _, err := tx.Exec(SQLRefreshActiveCheck, check_id, pq.Array(bytes.Fields(cmd.Bytes()))); err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
log.Printf("could not refresh check '%d': %s", check_id, err)
|
log.Printf("could not refresh check '%d': %s", check_id, err)
|
||||||
continue
|
continue
|
||||||
@ -184,35 +184,6 @@ func startConfigGen(db *sql.DB, checkInterval time.Duration) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func stringToShellFields(in []byte) [][]byte {
|
|
||||||
if len(in) == 0 {
|
|
||||||
return [][]byte{}
|
|
||||||
}
|
|
||||||
fields := bytes.Fields(in)
|
|
||||||
result := [][]byte{fields[0]}
|
|
||||||
|
|
||||||
var quote byte
|
|
||||||
|
|
||||||
for _, field := range fields[1:] {
|
|
||||||
if quote == 0 && (field[0] != '\'' && field[0] != '"') {
|
|
||||||
result = append(result, field)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if quote == 0 && (field[0] == '\'' || field[0] == '"') {
|
|
||||||
quote = field[0]
|
|
||||||
result = append(result, field)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
idx := len(result) - 1
|
|
||||||
result[idx] = append(result[idx], append([]byte(" "), field...)...)
|
|
||||||
if quote != 0 && (bytes.HasSuffix(field, []byte{quote})) {
|
|
||||||
quote = 0
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
SQLGetConfigUpdates = `select c.id, co.command, c.options
|
SQLGetConfigUpdates = `select c.id, co.command, c.options
|
||||||
from checks c
|
from checks c
|
||||||
|
Loading…
Reference in New Issue
Block a user