@@ -944,6 +944,26 @@ func (cd *CheckData) HasMacro(name string) bool {
944944 return false
945945}
946946
947+ // AllRequiredMacros returns a list of all required macros in the syntax attributes and thresholds.
948+ func (cd * CheckData ) AllRequiredMacros () []string {
949+ var allMacros []string
950+
951+ // extract macros from syntax templates
952+ for _ , syntax := range []string {cd .detailSyntax , cd .topSyntax , cd .okSyntax , cd .emptySyntax , cd .perfSyntax } {
953+ macros := MacroNames (syntax )
954+ allMacros = append (allMacros , macros ... )
955+ }
956+
957+ // append macros from all conditions
958+ allMacros = append (allMacros , cd .GetAllThresholdKeywords ()... )
959+
960+ // make list unique
961+ slices .Sort (allMacros )
962+ allMacros = slices .Compact (allMacros )
963+
964+ return allMacros
965+ }
966+
947967// apply condition aliases to all filter/warn/crit/ok conditions.
948968// this is useful for example in service checks, when people match for state running / started
949969func (cd * CheckData ) applyConditionAlias () {
@@ -984,10 +1004,28 @@ func (cd *CheckData) HasThreshold(name string) bool {
9841004 if cd .hasThresholdCond (cd .critThreshold , name ) {
9851005 return true
9861006 }
1007+ if cd .hasThresholdCond (cd .okThreshold , name ) {
1008+ return true
1009+ }
9871010
9881011 return false
9891012}
9901013
1014+ // GetAllThresholdKeywords returns a list of all keywords used in warn/crit/ok thresholds.
1015+ func (cd * CheckData ) GetAllThresholdKeywords () []string {
1016+ keywords := []string {}
1017+
1018+ keywords = append (keywords , cd .getAllThresholdKeywords (cd .warnThreshold )... )
1019+ keywords = append (keywords , cd .getAllThresholdKeywords (cd .critThreshold )... )
1020+ keywords = append (keywords , cd .getAllThresholdKeywords (cd .okThreshold )... )
1021+
1022+ // make list unique
1023+ slices .Sort (keywords )
1024+ keywords = slices .Compact (keywords )
1025+
1026+ return keywords
1027+ }
1028+
9911029// hasThresholdCond returns true is the given list of conditions uses the given name at least once.
9921030func (cd * CheckData ) hasThresholdCond (condList ConditionList , name string ) bool {
9931031 for _ , cond := range condList {
@@ -1003,6 +1041,21 @@ func (cd *CheckData) hasThresholdCond(condList ConditionList, name string) bool
10031041 return false
10041042}
10051043
1044+ // hasThresholdCond returns true is the given list of conditions uses the given name at least once.
1045+ func (cd * CheckData ) getAllThresholdKeywords (condList ConditionList ) []string {
1046+ keywords := []string {}
1047+
1048+ for _ , cond := range condList {
1049+ if len (cond .group ) > 0 {
1050+ keywords = append (keywords , cd .getAllThresholdKeywords (cond .group )... )
1051+ }
1052+
1053+ keywords = append (keywords , cond .keyword )
1054+ }
1055+
1056+ return keywords
1057+ }
1058+
10061059// SetDefaultThresholdUnit sets default unit for all threshold conditions matching
10071060// the name and not having a unit already
10081061func (cd * CheckData ) SetDefaultThresholdUnit (defaultUnit string , names []string ) {
0 commit comments