Re: [Shinken-devel] Patch for -use properties
Status: Beta
Brought to you by:
naparuba
From: Francois M. <fm...@ac...> - 2012-10-25 03:10:20
|
Hello, Thank you for your development time. You can submit patches in two ways: Method 1: Changes once in a while 1 - Install git 2 - git clone https://github.com/naparuba/shinken.git 3 - copy your changes into the clone 4 - git -a -m "Add: Super changes" 5 - git diff 6 - Open an issue and paste your diff (or put a link to the git diff files in paste bin) Method 2: Many changes in the pipeline 1 - Create a github account 2 - Fork shinken 3 - Install git on a linux workstation/server 4 - git clone your github forked shinken repository using HTTPS 5 - Configure a remote for (naparuba/shinken) and fetch any changes 6 - Merge any changes from naparuba/shinken and then commit/push them back to your github fork 7 - You are now up to date 8 - Switch to a branch 9 - Do your changes 10 - Run the test suite (and add new tests...) 11 - commit and push back to your github 12 - In naparuba/shinken do a pull request against your branch 13 - Rule the world! I would suggest you use Method 1. And create an issue with a git diff. xkilian On 12-10-24 8:18 PM, Joel Ramat wrote: > Hello Shinken developers, > > I write a patch to add '-use' feature on discovery rules like this : > > define discoveryrule { > discoveryrule_name RouterOS > creation_type host > macvendor routerboard.com <http://routerboard.com> > openports ^8291$ > +use http,router-os > -use linux > } > > This patch add an other feature, he do not duplicate properties in the > final stage like this : > > define discoveryrule { > discoveryrule_name RouterOS > creation_type host > macvendor routerboard.com <http://routerboard.com> > openports ^8291$ > +use http,router-os,router-os > -use linux > } > > define host { > use ftp,http,dns,ssh,router-os,generic-host > host_name 172.17.17.1 > address 172.17.17.1 > } > > I do not know how to offer you the patch, I give you below the mods done : > > In file /usr/local/shinken/shinken/discovery/discoverymanager.py > > Add 'import string' > > and change the function update_properties() > > def update_properties(self, final_phase=False): > d = {} > if final_phase: > for (k,v) in self.data.iteritems(): > if k.startswith('_'): > d[k] = v > else: > d = copy.copy(self.data) > > d['host_name'] = self.name <http://self.name> > # Set address directive if an ip exists > if self.data.has_key('ip'): > d['address'] = self.data['ip'] > > self.matched_rules.sort(by_order) > > for r in self.matched_rules: > for k,v in r.writing_properties.iteritems(): > # If it's a + (add) property, append > if k.startswith('+'): > lprop = k[1:] > # If the d do not already have this prop, > # create list and append it > if not lprop in d: > print 'New prop',lprop > d[lprop]=[] > for prop in string.split(v,','): > #check for no duplicate prop and append > if not prop in d[lprop]: > d[lprop].append(prop) > # oh, just append > else: > for prop in string.split(v,','): > #check for no duplicate prop and append > if not prop in d[lprop]: > print 'Already got', ','.join(d[lprop]), 'add', prop > d[lprop].append(prop) > elif not k.startswith('-'): > lprop = k > if not lprop in d: > print 'New prop',lprop > else: > print 'Prop',lprop,'reset with new value' > d[lprop]=[] > for prop in string.split(v,','): > #check for no duplicate prop and append > if not prop in d[lprop]: > d[lprop].append(prop) > > # Now look for - (rem) property > for k,v in r.writing_properties.iteritems(): > if k.startswith('-'): > lprop = k[1:] > if lprop in d: > for prop in string.split(v,','): > if prop in d[lprop]: > print 'Already got', ','.join(d[lprop]), 'rem', prop > d[lprop].remove(prop) > > # Change join prop list in string with a ',' separator > for (k,v) in d.iteritems(): > if type(d[k]).__name__=='list': > d[k]=','.join(d[k]) > > self.properties = d > print 'Update our properties', self.name <http://self.name>, d > > # For macro-resolving, we should have our macros too > self.customs = {} > for (k,v) in self.properties.iteritems(): > self.customs['_'+k.upper()] = v > > In file shinken/objects/discoveryrule.py > > # In my own property: > # -> in __dict__ > # In the properties of the 'creation_type' Class: > # -> in self.writing_properties > # if not, in matches or not match (if key starts > # with a !, it's a not rule) > # -> in self.matches or self.not_matches > # in writing properties if start with + (means 'add this') > # in writing properties if start with - (means 'rem this') > for key in params: > # Some key are quite special > if key in cls.properties: > setattr(self, key, params[key]) > elif key in ['use'] or key.startswith('+') or key.startswith('-') or > key in tcls.properties or key.startswith('_'): > self.writing_properties[key] = params[key] > else: > if key.startswith('!'): > key = key.split('!')[1] > self.not_matches[key] = params['!' + key] > else: > self.matches[key] = params[key] > > > I'm not python developer (it's my first time with it) and i speak > english very bad (sorry). > > I await your comments... > > 6jo6jo > > > ------------------------------------------------------------------------------ > Everyone hates slow websites. So do we. > Make your web apps faster with AppDynamics > Download AppDynamics Lite for free today: > http://p.sf.net/sfu/appdyn_sfd2d_oct > > > _______________________________________________ > Shinken-devel mailing list > Shi...@li... > https://lists.sourceforge.net/lists/listinfo/shinken-devel |