-
Notifications
You must be signed in to change notification settings - Fork 5
/
evaluate_rule.pp
65 lines (53 loc) · 1.04 KB
/
evaluate_rule.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Evaluate a single expression made up of a left, right and operator
#
# @return [Boolean]
function classifier::evaluate_rule (
Data $left,
Classifier::Operators $operator,
Data $right,
Boolean $invert
) {
$evaluated = case $operator {
"==": {
$left == $right
}
"=~": {
$left =~ $right
}
">": {
versioncmp($left, $right) == 1
}
"=>": {
versioncmp($left, $right) != -1
}
"<": {
versioncmp($left, $right) == -1
}
"<=": {
versioncmp($left, $right) != 1
}
"in": {
$left in $right
}
"has_mac": {
classifier::has_interface_detail($right, "mac")
}
"has_ip_address": {
classifier::has_interface_detail($right, "address")
}
"has_ip_netmask": {
classifier::has_interface_detail($right, "netmask")
}
"has_ip_network": {
classifier::has_interface_detail($right, "network")
}
default: {
fail("Unknown operator ${operator}")
}
}
if $invert {
!$evaluated
} else {
$evaluated
}
}