github.com/crowdsecurity/crowdsec@v1.6.1/pkg/models/helpers.go (about)

     1  package models
     2  
     3  func (a *Alert) HasRemediation() bool {
     4  	return true
     5  }
     6  
     7  func (a *Alert) GetScope() string {
     8  	if a.Source.Scope == nil {
     9  		return ""
    10  	}
    11  	return *a.Source.Scope
    12  }
    13  
    14  func (a *Alert) GetValue() string {
    15  	if a.Source.Value == nil {
    16  		return ""
    17  	}
    18  	return *a.Source.Value
    19  }
    20  
    21  func (a *Alert) GetScenario() string {
    22  	if a.Scenario == nil {
    23  		return ""
    24  	}
    25  	return *a.Scenario
    26  }
    27  
    28  func (a *Alert) GetEventsCount() int32 {
    29  	if a.EventsCount == nil {
    30  		return 0
    31  	}
    32  	return *a.EventsCount
    33  }
    34  
    35  func (e *Event) GetMeta(key string) string {
    36  	for _, meta := range e.Meta {
    37  		if meta.Key == key {
    38  			return meta.Value
    39  		}
    40  	}
    41  	return ""
    42  }
    43  
    44  func (a *Alert) GetMeta(key string) string {
    45  	for _, meta := range a.Meta {
    46  		if meta.Key == key {
    47  			return meta.Value
    48  		}
    49  	}
    50  	return ""
    51  }
    52  
    53  func (s Source) GetValue() string {
    54  	if s.Value == nil {
    55  		return ""
    56  	}
    57  	return *s.Value
    58  }
    59  
    60  func (s Source) GetScope() string {
    61  	if s.Scope == nil {
    62  		return ""
    63  	}
    64  	return *s.Scope
    65  }
    66  
    67  func (s Source) GetAsNumberName() string {
    68  	ret := ""
    69  	if s.AsNumber != "0" {
    70  		ret += s.AsNumber
    71  	}
    72  	if s.AsName != "" {
    73  		ret += " " + s.AsName
    74  	}
    75  	return ret
    76  }