libMonitor

package module
v0.0.0-...-4fc7b4e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2019 License: MIT Imports: 12 Imported by: 0

README

libMonitor

a common monitor library

1、Dingtalk Reporter
2、Email reporter
3、Scan Interval Conf
4、Keep scan
5、Easy to rewrite Report

 
func main(){

    libMonitor.ScanInterval = 30
    libMonitor.ScaningInterval = 5
    libMonitor.ReportType ="email" //dingtalk or email
    //libMonitor.DingtalUrl="https://oapi.dingtalk.com/robot/send?access_token=xx"
    //libMonitor.DingtalkAtAll=false
    //libMonitor.DingtalTels=["1583331xxx"]
    libMonitor.SmtpHost="smtp.gmail.com"
    libMonitor.SmtpSender="sample@gmail.com"
    libMonitor.SmtpRecever=["recevor@gmail.com"]
    libMonitor.SmtpPort=25

    libMonitor.SetScanner(&MyScanner{})
    libMonitor.Start()
}


type MyScanner struct{}
var failCnt = 0
func (MyScanner)Scan() *ScanResult{

    if failCnt < 10 {
        return libMonitor.NewResult(true,fmt.sprintf("Failed at %d ",failCnt))
    }
    return libMonitor.NewResult(true,"success")


}




Custome Reporter

type MyReporter struct{}
func (MyReporter) Report (msg string) {
    fmt.println(msg)
}
libMonitor.AddReporter(&MyReporter{})


Documentation

Index

Constants

This section is empty.

Variables

View Source
var AgainReportBaseInterval = time.Duration(60 * time.Second)
View Source
var AgainReportMaxInterval = time.Duration(60 * 60 * time.Second) //1hour
View Source
var DingtalTels []string
View Source
var DingtalkAtAll = false
View Source
var DingtalkUrl = "https://oapi.dingtalk.com/robot/send?access_token=32e0699c542e314680b05a9c947577395b86389bd4fe2853181b14b055c4a5ed"
View Source
var KeepRunning = true
View Source
var Lang_First_Report = "%s first Fail\nmsg:%s"
View Source
var Lang_ReportAgain = "%s scan count %d, duration time:%s\n msg:%s"
View Source
var Lang_ReportRecover = "%s is recover, duration time:%s"
View Source
var Logger midlog.Midlog = midlog.New("libMonitor")
View Source
var MonitorName = "My Monitor"
View Source
var ReportType = "email" //dingtalk or email
View Source
var ScanInterval = time.Duration(30 * time.Second)
View Source
var ScaningInterval = time.Duration(5 * time.Second)
View Source
var SmtpHost = ""
View Source
var SmtpPort = 25
View Source
var SmtpPwd = ""
View Source
var SmtpRecever []string //aa@gmail.com,bb@yahoo.com
View Source
var SmtpSender = ""
View Source
var SmtpUserName = ""
View Source
var StartFailedTime time.Time

Functions

func AddReporter

func AddReporter(newReporter IReporter)

func ClearReporter

func ClearReporter(newReporter IReporter)

func Done

func Done()

func GetAgainReportBaseInterval

func GetAgainReportBaseInterval() time.Duration

func GetAgainReportMaxInterval

func GetAgainReportMaxInterval() time.Duration

func GetDingtalTels

func GetDingtalTels() []string

func GetDingtalkAtAll

func GetDingtalkAtAll() bool

func GetDingtalkUrl

func GetDingtalkUrl() string

func GetKeepRunning

func GetKeepRunning() bool

func GetMonitorName

func GetMonitorName() string

func GetReportType

func GetReportType() string

func GetScanInterval

func GetScanInterval() time.Duration

func GetScaningInterval

func GetScaningInterval() time.Duration

func GetSmtpHost

func GetSmtpHost() string

func GetSmtpPort

func GetSmtpPort() int

func GetSmtpPwd

func GetSmtpPwd() string

func GetSmtpRecever

func GetSmtpRecever() []string

func GetSmtpSender

func GetSmtpSender() string

func GetSmtpUserName

func GetSmtpUserName() string

func InitReports

func InitReports()

func SetAgainReportBaseInterval

func SetAgainReportBaseInterval(val time.Duration)

func SetAgainReportBaseIntervalFromStr

func SetAgainReportBaseIntervalFromStr(val string) error

func SetAgainReportMaxInterval

func SetAgainReportMaxInterval(val time.Duration)

func SetAgainReportMaxIntervalFromStr

func SetAgainReportMaxIntervalFromStr(val string) error

func SetDingtalTels

func SetDingtalTels(val []string)

func SetDingtalkAtAll

func SetDingtalkAtAll(val bool)

func SetDingtalkUrl

func SetDingtalkUrl(val string)

func SetKeepRunning

func SetKeepRunning(val bool)

func SetMonitorName

func SetMonitorName(val string)

func SetReportType

func SetReportType(val string)

func SetScanInterval

func SetScanInterval(val time.Duration)

func SetScanIntervalFromStr

func SetScanIntervalFromStr(val string) error

func SetScaningInterval

func SetScaningInterval(val time.Duration)

func SetScaningIntervalFromStr

func SetScaningIntervalFromStr(val string) error

func SetScanner

func SetScanner(newScanner IScaner)

func SetSmtpHost

func SetSmtpHost(val string)

func SetSmtpPort

func SetSmtpPort(val int)

func SetSmtpPwd

func SetSmtpPwd(val string)

func SetSmtpRecever

func SetSmtpRecever(val []string)

func SetSmtpSender

func SetSmtpSender(val string)

func SetSmtpUserName

func SetSmtpUserName(val string)

func Start

func Start()

* libMonitor main function

func TrigReport

func TrigReport(msg string)

Types

type DingtalkReporter

type DingtalkReporter struct{}

func (DingtalkReporter) Report

func (DingtalkReporter) Report(msg string)

type EmailReporter

type EmailReporter struct{}

func (EmailReporter) Report

func (EmailReporter) Report(msg string)

type IReporter

type IReporter interface {
	Report(msg string)
}

type IScaner

type IScaner interface {
	Scan() *ScanResult
}

* Scan interface

type ScanResult

type ScanResult struct {
	Success bool
	Msg     string
	// contains filtered or unexported fields
}

* Result of IScaner invoke

func NewResult

func NewResult(success bool, msg string) *ScanResult

Get a New Result of Scan

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL