Skip to content
Browse files

Add : discoveryrule_order so the admin can manage the template order …

…in a more easy way than with the order in the file... By default I put generic-host as the last one with a huge order 999. The default is 0, so put -1 wil go before unset rules.
  • Loading branch information...
1 parent b04345d commit 5089ba9b02c84bcacc375efbd484928cf67d2aff @naparuba committed May 6, 2012
View
4 etc/discovery_rules.cfg
@@ -5,6 +5,10 @@
define discoveryrule {
discoveryrule_name HostGeneric
creation_type host
+ # Generic host should be the last template use, so we give it the
+ # last order
+ discoveryrule_order 999
+
isup 1
+use generic-host
}
View
1 etc/discovery_runs.cfg
@@ -29,6 +29,7 @@ define command{
define discoveryrule {
discoveryrule_name Gentoo
+ discoveryrule_order -1
creation_type host
distrib gentoo
+use gentoo-linux
View
3 libexec/fake_linux_discovery.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+echo "$1::distrib=gentoo"
View
3 libexec/fake_linux_gentoo_discovery.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+echo "$1::distribversion=gentooOLD"
View
12 shinken/discovery/discoverymanager.py
@@ -49,6 +49,15 @@ def is_ipv4_addr(name):
return (re.match(p, name) is not None)
+
+def by_order(r1, r2):
+ if r1.discoveryrule_order == r2.discoveryrule_order:
+ return 0
+ if r1.discoveryrule_order > r2.discoveryrule_order:
+ return 1
+ if r1.discoveryrule_order < r2.discoveryrule_order:
+ return -1
+
class DiscoveredHost(object):
my_type = 'host' # we fake our type for the macro resolving
@@ -73,6 +82,8 @@ def __init__(self, name, rules, runners):
def update_properties(self):
d = copy.copy(self.data)
d['host_name'] = self.name
+
+ self.matched_rules.sort(by_order)
for r in self.matched_rules:
for k,v in r.writing_properties.iteritems():
@@ -85,6 +96,7 @@ def update_properties(self):
d[prop] = v
# oh, must add with a , so
else:
+ print 'Already got', d[prop], 'add', v
d[prop] = d[prop] + ',' + v
else:
d[k] = v
View
3 shinken/objects/discoveryrule.py
@@ -31,7 +31,7 @@
from shinken.objects.matchingitem import MatchingItem
from service import Service
from host import Host
-from shinken.property import StringProp, ListProp
+from shinken.property import StringProp, ListProp, IntegerProp
class Discoveryrule(MatchingItem):
@@ -42,6 +42,7 @@ class Discoveryrule(MatchingItem):
properties.update({
'discoveryrule_name': StringProp (),
'creation_type': StringProp (default='service'),
+ 'discoveryrule_order': IntegerProp(default='0'),
# 'check_command': StringProp (),
# 'service_description': StringProp (),
# 'use': StringProp(),

0 comments on commit 5089ba9

Please sign in to comment.
Something went wrong with that request. Please try again.