Compare commits
3 commits
master
...
check_mysq
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0cee7e7d37 | ||
![]() |
ab6f301467 | ||
![]() |
5c98cb2615 |
5 changed files with 0 additions and 142 deletions
|
@ -6,8 +6,3 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
Which is based on [Keep A Changelog](http://keepachangelog.com/)
|
Which is based on [Keep A Changelog](http://keepachangelog.com/)
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
# Added
|
|
||||||
|
|
||||||
- check for systemd service
|
|
||||||
- check count for a mysql query
|
|
||||||
|
|
23
README.md
23
README.md
|
@ -1,23 +0,0 @@
|
||||||
# Monitoring plugins
|
|
||||||
|
|
||||||
[](https://git.yaegashi.fr/nishiki/gpm/src/branch/master/LICENSE)
|
|
||||||
|
|
||||||
A collection of monitoring plugins for nagios-like monitoring
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
```text
|
|
||||||
Copyright (c) 2019 Adrien Waksberg
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
```
|
|
|
@ -1,19 +1,3 @@
|
||||||
/*
|
|
||||||
Copyright 2019 Adrien Waksberg
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
|
@ -1,97 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright 2019 Adrien Waksberg
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"flag"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Option to parse
|
|
||||||
var (
|
|
||||||
HELP = flag.Bool("help", false, "print the help message")
|
|
||||||
SERVICE = flag.String("service", "", "service name")
|
|
||||||
LIFETIME = flag.Int("lifetime", 60, "minimum life time in second")
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
if *HELP {
|
|
||||||
flag.PrintDefaults()
|
|
||||||
os.Exit(3)
|
|
||||||
}
|
|
||||||
|
|
||||||
if *SERVICE == "" {
|
|
||||||
Critical("Please set service name")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Critical print a message and exit with code 2
|
|
||||||
func Critical(msg string) {
|
|
||||||
fmt.Println(fmt.Sprintf("CRITICAL - %s", msg))
|
|
||||||
os.Exit(2)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warning print a message and exit with code 1
|
|
||||||
func Warning(msg string) {
|
|
||||||
fmt.Println(fmt.Sprintf("WARNING - %s", msg))
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ok print a message and exit with code 0
|
|
||||||
func Ok(msg string) {
|
|
||||||
fmt.Println(fmt.Sprintf("OK - %s", msg))
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ServiceStatus check if the service is started
|
|
||||||
func ServiceStatus() error {
|
|
||||||
cmd := exec.Command("systemctl", "is-active", *SERVICE)
|
|
||||||
if err := cmd.Run(); err != nil {
|
|
||||||
return fmt.Errorf("the service is inactive")
|
|
||||||
}
|
|
||||||
|
|
||||||
output, err := exec.Command("systemctl", "show", *SERVICE, "-p", "ExecMainStartTimestamp", "--value").Output()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
startDate, err := time.Parse("Mon 2006-01-02 15:04:05 MST", strings.Trim(string(output), "\n"))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if startDate.Unix() > time.Now().Add(- time.Duration(*LIFETIME) * time.Second).Unix() {
|
|
||||||
return fmt.Errorf("the service has started for less than %d seconds", *LIFETIME)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
err := ServiceStatus()
|
|
||||||
if err != nil {
|
|
||||||
Critical(fmt.Sprintf("%v", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok("the service is active")
|
|
||||||
}
|
|
1
go.mod
1
go.mod
|
@ -1 +0,0 @@
|
||||||
module monitoring-plugins
|
|
Loading…
Add table
Add a link
Reference in a new issue