本文整理匯總了Golang中github.com/elastic/libbeat/logp.Critical函數的典型用法代碼示例。如果您正苦於以下問題:Golang Critical函數的具體用法?Golang Critical怎麽用?Golang Critical使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Critical函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ConfigSetup
func (beat *Beat) ConfigSetup(beater Beater, inputConfig interface{}) {
config := &ConfigSettings{
//Input: inputConfig,
}
err := cfgfile.Read(config)
beat.Config = *config
if err != nil {
logp.Debug("Log read error", "Error %v\n", err)
}
logp.Init(beat.Name, &beat.Config.Logging)
logp.Debug("main", "Initializing output plugins")
if err := publisher.Publisher.Init(beat.Config.Output, beat.Config.Shipper); err != nil {
logp.Critical(err.Error())
os.Exit(1)
}
beat.events = publisher.Publisher.Queue
logp.Debug(beat.Name, "Init %s", beat.Name)
if err := beater.Init(beat); err != nil {
logp.Critical(err.Error())
os.Exit(1)
}
}
示例2: loadTLSConfig
func loadTLSConfig(config *TLSConfig) (*tlsConfig, error) {
var tlsconfig tlsConfig
// Support minimal TLS 1.0.
// TODO: check supported JRuby versions for logstash supported
// TLS 1.1 and switch
tlsconfig.MinVersion = tls.VersionTLS10
hasCertificate := config.Certificate != ""
hasKey := config.Key != ""
switch {
case hasCertificate && !hasKey:
return nil, ErrCertificateNoKey
case !hasCertificate && hasKey:
return nil, ErrKeyNoCertificate
case hasCertificate && hasKey:
cert, err := tls.LoadX509KeyPair(config.Certificate, config.Key)
if err != nil {
logp.Critical("Failed loading client certificate", err)
return nil, err
}
tlsconfig.Certificates = []tls.Certificate{cert}
}
if len(config.CAs) > 0 {
tlsconfig.RootCAs = x509.NewCertPool()
}
for _, caFile := range config.CAs {
pemData, err := ioutil.ReadFile(caFile)
if err != nil {
logp.Critical("Failed reading CA certificate: %s", err)
return nil, err
}
block, _ := pem.Decode(pemData)
if block == nil {
logp.Critical("Failed to decode PEM. Is certificate %s valid?", caFile)
return nil, ErrNotACertificate
}
if block.Type != "CERTIFICATE" {
logp.Critical("PEM File %s is not a certificate", caFile)
return nil, ErrNotACertificate
}
cert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
logp.Critical("Failed to parse certificate file %s", caFile)
return nil, ErrNotACertificate
}
tlsconfig.RootCAs.AddCert(cert)
}
return &tlsconfig, nil
}
示例3: LoadTLSConfig
// LoadTLSConfig will load a certificate from config with all TLS based keys
// defined. If Certificate and CertificateKey are configured, client authentication
// will be configured. If no CAs are configured, the host CA will be used by go
// built-in TLS support.
func LoadTLSConfig(config MothershipConfig) (*tls.Config, error) {
certificate := config.Certificate
key := config.CertificateKey
rootCAs := config.CAs
hasCertificate := certificate != ""
hasKey := key != ""
var certs []tls.Certificate
switch {
case hasCertificate && !hasKey:
return nil, ErrCertificateNoKey
case !hasCertificate && hasKey:
return nil, ErrKeyNoCertificate
case hasCertificate && hasKey:
cert, err := tls.LoadX509KeyPair(certificate, key)
if err != nil {
logp.Critical("Failed loading client certificate", err)
return nil, err
}
certs = []tls.Certificate{cert}
}
var roots *x509.CertPool
if len(rootCAs) > 0 {
roots = x509.NewCertPool()
for _, caFile := range rootCAs {
pemData, err := ioutil.ReadFile(caFile)
if err != nil {
logp.Critical("Failed reading CA certificate: %s", err)
return nil, err
}
if ok := roots.AppendCertsFromPEM(pemData); !ok {
return nil, ErrNotACertificate
}
}
}
insecureSkipVerify := false
if config.TLSInsecure != nil {
insecureSkipVerify = *config.TLSInsecure
}
// Support minimal TLS 1.0.
// TODO: check supported JRuby versions for logstash supported
// TLS 1.1 and switch
tlsConfig := tls.Config{
MinVersion: tls.VersionTLS10,
Certificates: certs,
RootCAs: roots,
InsecureSkipVerify: insecureSkipVerify,
}
return &tlsConfig, nil
}
示例4: Run
func (pb *Packetbeat) Run(b *beat.Beat) error {
// run the sniffer in background
go func() {
err := pb.Sniff.Run()
if err != nil {
logp.Critical("Sniffer main loop failed: %v", err)
os.Exit(1)
}
pb.over <- true
}()
// Startup successful, disable stderr logging if requested by
// cmdline flag
logp.SetStderr()
logp.Debug("main", "Waiting for the sniffer to finish")
// Wait for the goroutines to finish
for _ = range pb.over {
if !pb.Sniff.IsAlive() {
break
}
}
waitShutdown := pb.CmdLineArgs.WaitShutdown
if waitShutdown != nil && *waitShutdown > 0 {
time.Sleep(time.Duration(*waitShutdown) * time.Second)
}
return nil
}
示例5: main
func main() {
// Create Beater object
fb := &filebeat.Filebeat{}
// Initi beat objectefile
b := beat.NewBeat(Name, Version, fb)
// Additional command line args are used to overwrite config options
b.CommandLineSetup()
// Loads base config
b.LoadConfig()
// Configures beat
err := fb.Config(b)
if err != nil {
logp.Critical("Config error: %v", err)
os.Exit(1)
}
// Run beat. This calls first beater.Setup,
// then beater.Run and beater.Cleanup in the end
b.Run()
}
示例6: LoadConfig
// LoadConfig inits the config file and reads the default config information
// into Beat.Config. It exists the processes in case of errors.
func (b *Beat) LoadConfig() {
err := cfgfile.Read(&b.Config, "")
if err != nil {
// logging not yet initialized, so using fmt.Printf
fmt.Printf("%v\n", err)
os.Exit(1)
}
err = logp.Init(b.Name, &b.Config.Logging)
if err != nil {
fmt.Printf("Error initializing logging: %v\n", err)
os.Exit(1)
}
logp.Debug("beat", "Initializing output plugins")
if err := publisher.Publisher.Init(b.Name, b.Version, b.Config.Output, b.Config.Shipper); err != nil {
logp.Critical(err.Error())
os.Exit(1)
}
b.Events = publisher.Publisher.Client()
logp.Debug("beat", "Init %s", b.Name)
}
示例7: LoadConfig
// LoadConfig inits the config file and reads the default config information
// into Beat.Config. It exists the processes in case of errors.
func (b *Beat) LoadConfig() {
err := cfgfile.Read(&b.Config, "")
if err != nil {
// logging not yet initialized, so using fmt.Printf
fmt.Printf("Loading config file error: %v\n", err)
os.Exit(1)
}
err = logp.Init(b.Name, &b.Config.Logging)
if err != nil {
fmt.Printf("Error initializing logging: %v\n", err)
os.Exit(1)
}
// Disable stderr logging if requested by cmdline flag
logp.SetStderr()
logp.Debug("beat", "Initializing output plugins")
if err := publisher.Publisher.Init(b.Name, b.Config.Output, b.Config.Shipper); err != nil {
fmt.Printf("Error Initialising publisher: %v\n", err)
logp.Critical(err.Error())
os.Exit(1)
}
b.Events = publisher.Publisher.Client()
logp.Debug("beat", "Init %s", b.Name)
}
示例8: Run
func (p *Pingbeat) Run(b *beat.Beat) error {
p.isAlive = true
fp := fastping.NewPinger()
errInput, err := fp.Network(p.pingType)
if err != nil {
logp.Critical("Error: %v (input %v)", err, errInput)
os.Exit(1)
}
if p.useIPv4 {
for addr, details := range p.ipv4targets {
logp.Debug("pingbeat", "Adding target IP: %s, Name: %s, Tag: %s\n", addr, details[0], details[1])
fp.AddIP(addr)
}
}
if p.useIPv6 {
for addr, details := range p.ipv6targets {
logp.Debug("pingbeat", "Adding target IP: %s, Name: %s, Tag: %s\n", addr, details[0], details[1])
fp.AddIP(addr)
}
}
fp.OnRecv = func(addr *net.IPAddr, rtt time.Duration) {
var name, tag string
ip := addr.IP
if ip.To4() != nil {
name = p.ipv4targets[addr.String()][0]
tag = p.ipv4targets[addr.String()][1]
} else {
name = p.ipv6targets[addr.String()][0]
tag = p.ipv6targets[addr.String()][1]
}
event := common.MapStr{
"timestamp": common.Time(time.Now()),
"type": "pingbeat",
"target_name": name,
"target_addr": addr.String(),
"tag": tag,
"rtt": milliSeconds(rtt),
}
p.events.PublishEvent(event)
}
// fp.OnIdle = func() {
// fmt.Println("loop done")
// }
for p.isAlive {
time.Sleep(p.period)
err := fp.Run()
if err != nil {
logp.Warn("Warning: %v", err)
}
}
return nil
}
示例9: Config
func (p *Pingbeat) Config(b *beat.Beat) error {
// Read in provided config file, bail if problem
err := cfgfile.Read(&p.config, "")
if err != nil {
logp.Err("Error reading configuration file: %v", err)
return err
}
// Use period provided in config or default to 5s
if p.config.Input.Period != nil {
p.period = time.Duration(*p.config.Input.Period) * time.Second
} else {
p.period = 5 * time.Second
}
logp.Debug("pingbeat", "Period %v\n", p.period)
// Check if we can use privileged (i.e. raw socket) ping,
// else use a UDP ping
if *p.config.Input.Privileged {
p.pingType = "ip"
} else {
p.pingType = "udp"
}
logp.Debug("pingbeat", "Using %v for pings\n", p.pingType)
// Check whether IPv4/IPv6 pings are requested in config
// Default to just IPv4 pings
if &p.config.Input.UseIPv4 != nil {
p.useIPv4 = *p.config.Input.UseIPv4
} else {
p.useIPv4 = true
}
if &p.config.Input.UseIPv6 != nil {
p.useIPv6 = *p.config.Input.UseIPv6
} else {
p.useIPv6 = false
}
logp.Debug("pingbeat", "IPv4: %v, IPv6: %v\n", p.useIPv4, p.useIPv6)
// Fill the IPv4/IPv6 targets maps
p.ipv4targets = make(map[string][2]string)
p.ipv6targets = make(map[string][2]string)
if p.config.Input.Targets != nil {
for tag, targets := range *p.config.Input.Targets {
for i := 0; i < len(targets); i++ {
p.AddTarget(targets[i], tag)
}
}
} else {
logp.Critical("Error: no targets specified, cannot continue!")
os.Exit(1)
}
return nil
}
示例10: Run
// Run calls the beater Setup and Run methods. In case of errors
// during the setup phase, it exits the process.
func (b *Beat) Run() {
// Setup beater object
err := b.BT.Setup(b)
if err != nil {
logp.Critical("Setup returned an error: %v", err)
os.Exit(1)
}
// Up to here was the initialization, now about running
if cfgfile.IsTestConfig() {
// all good, exit with 0
os.Exit(0)
}
service.BeforeRun()
// Callback is called if the processes is asked to stop.
// This needs to be called before the main loop is started so that
// it can register the signals that stop or query (on Windows) the loop.
service.HandleSignals(b.BT.Stop)
// Startup successful, disable stderr logging if requested by
// cmdline flag
logp.SetStderr()
// Run beater specific stuff
err = b.BT.Run(b)
if err != nil {
logp.Critical("Run returned an error: %v", err)
}
service.Cleanup()
logp.Debug("beat", "Cleanup")
// Call beater cleanup function
err = b.BT.Cleanup(b)
if err != nil {
logp.Err("Cleanup returned an error: %v", err)
}
}
示例11: Run
// Run calls the beater Setup and Run methods. In case of errors
// during the setup phase, it exits the process.
func (b *Beat) Run() {
// Setup beater object
err := b.BT.Setup(b)
if err != nil {
logp.Critical("Setup returned an error: %v", err)
os.Exit(1)
}
// Up to here was the initialization, now about running
if cfgfile.IsTestConfig() {
// all good, exit with 0
os.Exit(0)
}
service.BeforeRun()
// Callback is called if the processes is asked to stop.
// This needs to be called before the main loop is started so that
// it can register the signals that stop or query (on Windows) the loop.
service.HandleSignals(b.BT.Stop)
logp.Info("%s sucessfully setup. Start running.", b.Name)
// Run beater specific stuff
err = b.BT.Run(b)
if err != nil {
logp.Critical("Run returned an error: %v", err)
}
service.Cleanup()
logp.Info("Cleaning up %s before shutting down.", b.Name)
// Call beater cleanup function
err = b.BT.Cleanup(b)
if err != nil {
logp.Err("Cleanup returned an error: %v", err)
}
}
示例12: Start
func (crawler *Crawler) Start(files []config.ProspectorConfig, eventChan chan *input.FileEvent) {
pendingProspectorCnt := 0
crawler.running = true
// Prospect the globs/paths given on the command line and launch harvesters
for _, fileconfig := range files {
logp.Debug("prospector", "File Configs: %v", fileconfig.Paths)
prospector := &Prospector{
ProspectorConfig: fileconfig,
registrar: crawler.Registrar,
}
err := prospector.Init()
if err != nil {
logp.Critical("Error in initing prospector: %s", err)
fmt.Printf("Error in initing prospector: %s", err)
os.Exit(1)
}
go prospector.Run(eventChan)
pendingProspectorCnt++
}
// Now determine which states we need to persist by pulling the events from the prospectors
// When we hit a nil source a prospector had finished so we decrease the expected events
logp.Debug("prospector", "Waiting for %d prospectors to initialise", pendingProspectorCnt)
for event := range crawler.Registrar.Persist {
if event.Source == nil {
pendingProspectorCnt--
if pendingProspectorCnt == 0 {
logp.Debug("prospector", "No pending prospectors. Finishing setup")
break
}
continue
}
crawler.Registrar.State[*event.Source] = event
logp.Debug("prospector", "Registrar will re-save state for %s", *event.Source)
if !crawler.running {
break
}
}
logp.Info("All prospectors initialised with %d states to persist", len(crawler.Registrar.State))
}
示例13: Config
func (p *Pingbeat) Config(b *beat.Beat) error {
err := cfgfile.Read(&p.config, "")
if err != nil {
logp.Err("Error reading configuration file: %v", err)
return err
}
if p.config.Input.Period != nil {
p.period = time.Duration(*p.config.Input.Period) * time.Second
} else {
p.period = 1 * time.Second
}
logp.Debug("pingbeat", "Period %v\n", p.period)
if *p.config.Input.Privileged {
p.pingType = "ip"
} else {
p.pingType = "udp"
}
logp.Debug("pingbeat", "Using %v for pings\n", p.pingType)
if &p.config.Input.UseIPv4 != nil {
p.useIPv4 = *p.config.Input.UseIPv4
} else {
p.useIPv4 = true
}
if &p.config.Input.UseIPv6 != nil {
p.useIPv6 = *p.config.Input.UseIPv6
} else {
p.useIPv6 = false
}
logp.Debug("pingbeat", "IPv4: %v, IPv6: %v\n", p.useIPv4, p.useIPv6)
p.ipv4targets = make(map[string][2]string)
p.ipv6targets = make(map[string][2]string)
if p.config.Input.Targets != nil {
for tag, targets := range *p.config.Input.Targets {
for i := 0; i < len(targets); i++ {
p.AddTarget(targets[i], tag)
}
}
} else {
logp.Critical("Error: no targets specified, cannot continue!")
os.Exit(1)
}
return nil
}
示例14: main
func main() {
gb := &Gzipbeat{}
b := beat.NewBeat(Name, Version, gb)
b.CommandLineSetup()
b.LoadConfig()
err := gb.Config(b)
if err != nil {
logp.Critical("Config error: %v", err)
os.Exit(1)
}
b.Run()
}
示例15: IsRegularFile
// Check that the file isn't a symlink, mode is regular or file is nil
func (f *File) IsRegularFile() bool {
if f.File == nil {
logp.Critical("Harvester: BUG: f arg is nil")
return false
}
info, e := f.File.Stat()
if e != nil {
logp.Err("File check fault: stat error: %s", e.Error())
return false
}
if !info.Mode().IsRegular() {
logp.Warn("Harvester: not a regular file: %q %s", info.Mode(), info.Name())
return false
}
return true
}