An extensible monitoring tool for user defined services and protocols, all wrote in GoLang.
- This project is in BETA stage
- Go version : 1.15
BigBro Core is the core library of the main project BigBro, it can be used in standalone way (without any web service or user interface, recommend for low specs devices (as OrangePi or others).
- http
- https (with ssl)
- icmp
- icmp6
In the configuration file will must be defined all services and protocol to be monitor. The format type of the file is YAML as follows:
services:
- name: Facebook (ssl)
protocols:
- type: https
port: 443
server: facebook.com
interval : 1000
- name: Google
protocols:
- type: http
server: google.com
interval : 1000
- name: Google DNS
protocols:
- type: icmp
server: 8.8.8.8
interval : 1000
- name: Google DNS6
protocols:
- type: icmp6
server: 2a00:1450:400a:804::2004
interval : 5000
- type: ftp
server: 1.1.1.1
interval : 1000
customs :
user : uss
password : passwd
...
name
: Name of the serviceprotocols
: List of protocols that would be monitoredtype
: name of registered protocolserver
: IP or dns of serviceinterval
: interval time between check (in milliseconds)port
: (optional) port of servicecustoms
: (optional) list of custom filed for custom implementation of protocols
BigBro core structured in two main parts: protocolInterface
and responseHandlerInterface
.
BigBro Core allows the implementation of new type of network protocol or services to be monitor. To develop an implementation the developer must implements the protocolInterface
, in particular the developer must implement the CheckService
function, and the struct that defines the protocol or service.
In the CheckService
function must be defined the check login of the specified protocol / service and then return the error
(if occurred) or nil
.
An example of implementation of a http protocol:
package protocols
import (
"github.com/bigbroproject/bigbrocore/models"
httplib "net/http"
"strconv"
"time"
)
type Http struct {
}
// If error is nil, then service is up
func (http Http) CheckService(Protocol models.Protocol) error {
// CHECK
tr := &httplib.Transport{
MaxIdleConns: 10,
IdleConnTimeout: 30 * time.Second,
}
client := &httplib.Client{Transport: tr}
url := "http://" + Protocol.Server
if Protocol.Port == 0 {
url += ":80"
} else {
url += ":" + strconv.Itoa(Protocol.Port)
}
_, err := client.Get(url)
return err
}
In this example the CheckService
try to perform a simply GET via http to the specific server or service and then return the http error if occurred, nil
otherwise.
A responseHandlers receives the responses (the responses are define by the models/response/Response
struct) from the monitoring process, defined by the config files and registered protocols.
A struct that defines the handler and a Handle
function must be implemented to mange the received Response
from the monitoring processes. It must had an infinite loop to manage the receiving Responses.
A response is structured as follow:
type ResponseType string
const (
Success ResponseType = "Success"
Error = "Error"
)
type Response struct {
ServiceName string // The service name defined in configuration file
Protocol models.Protocol // The protocol used to monitoring defined in configuration file
ResponseType ResponseType // The ReponseType (Success or Error)
Error error // The error if there is any
}
The channel which is passed as input in Handle
function is used where the responses arrive.
Following, an example of ConsoleHandler
, that simply prints the Responses
in console:
package responsehandlers
import (
"fmt"
"github.com/bigbroproject/bigbrocore/models/response"
"github.com/fatih/color"
"log"
"strconv"
"time"
)
type ConsoleHandler struct {}
/*
Handle - manage the responses
configuration - is the same configuration model loaded from configFile
channel - is the channel where responses arrive from check processes
*/
func ( handler ConsoleHandler) Handle(configuration *models.Config, channel *chan response.Response){
for { //the infinite loop
resp := <- *channel // the receiving response
if resp.ResponseType == response.Error {
message = fmt.Sprintf("[%s] [%s] [%s] [%s - %s - %s] An error as accured: %s", "ERRO", now.Format(time.RFC3339), resp.ServiceName, resp.Protocol.Type, resp.Protocol.Server, port, resp.Error.Error())
} else {
message = fmt.Sprintf("[ %s ] [%s] [%s] [%s - %s - %s] Service seems OK.", "OK", now.Format(time.RFC3339), resp.ServiceName, resp.Protocol.Type, resp.Protocol.Server, port)
}
log.Println(message)
}
}
Firstly, before the usage of this library you must install this one as a go module:
go get -u github.com/bigbroproject/bigbrocore
After install process, you can create a main file for your project as follows:
package main
import (
"github.com/bigbroproject/bigbrocore/core"
"github.com/bigbroproject/bigbrocore/protocols"
"github.com/bigbroproject/bigbrocore/responsehandlers"
)
func main() {
regProtocolInterfaces, regResponseHandlerInterfaces := core.Initialize("PATH/TO/CONFIG_FILE.yml")
// Register custom protocol
protocols.RegisterProtocolInterface(®ProtocolInterfaces, "ftp", protocols.FTP{})
// Register custom Response Handler
responsehandlers.RegisterResponseHandlerInterface(®ResponseHandlerInterfaces, "consoleWithMemory", responsehandlers.ConsoleHandlerWithMemory{})
responsehandlers.RegisterResponseHandlerInterface(®ResponseHandlerInterfaces, "console", responsehandlers.ConsoleHandler{})
// Start monitoring
core.Start(regProtocolInterfaces, regResponseHandlerInterfaces)
}
In this example we Initialize
the entire module with a given configuration file path (you can mange this as a first input in your command line, for instance).
Secondly, you must define and register a ResponseHandler to manage the Responses from service checks (otherwise you cannot log or see anything) and then register a custom protocol, if needed.
Finally, you can over your project main with the Start
of the module.
Made with ❤️ by filirnd and fedyfausto