wiki:GrepModules
Last modified 7 years ago Last modified on 08/16/09 12:30:45

Grep Utility

Grep utility is actually a method in minion modules that can give

back some useful info about modules.Why someone may need it ?

Well the main idea is to have a utility method like "grep" which

maybe useful in troubleshooting or just filtering some info. Examples

are better than definitions :

Scanning the "service" and "smart" modules for "funcd" expression

[root@acerfedora func]# func "*" grep -m "service,smart" -v funcd

Scanning module : service
Scanning module : smart
{'acerfedora': [{'func.minion.modules.service.get_running': [['/usr/bin/funcd',
                                                              'running']]}]}

When using grep utility it is better to use it in async mode because you

may get the "connection timeout errors" Scanning all modules in system in async mode for keyword "funcd" :

[root@acerfedora func]# func "*" grep --async funcd

{'acerfedora': [{'func.minion.modules.process.info': ['root 5629 0.0 1.0 15724 9212 ? S 23:15 0:00 /usr/bin/python /usr/bin/funcd --daemon',
                                                      'root 8053 14.4 0.9 13920 8716 pts/0 S+ 23:37 0:03 /usr/bin/python /usr/bin/func * grep --async funcd',
                                                      'root 8235 7.0 0.0 0 0 ? Z 23:37 0:00 [funcd] <defunct>',
                                                      'root 8237 0.0 0.8 16692 8084 ? S 23:37 0:00 /usr/bin/python /usr/bin/funcd --daemon'],
                 'func.minion.modules.process.mem': ['1.7 MiB 2.6 MiB 4.3 MiB funcd']},
                {'func.minion.modules.service.get_running': [['/usr/bin/funcd',
                                                              'running']]}]}

Adding a utility method like that one is really easy. Here is example of

service.grep method :

@func_module.findout
    def grep(self,word):
        """
        Dig for some useful info in that module ...
        """
        final_dict = {self.get_running:[],
                      self.get_enabled:[]      
                }
        running = self.get_running()
        enabled = self.get_enabled()
        
        #get enabled ones
        for e in enabled:
            if e[0].lower().find(word)!=-1:
                final_dict[self.get_enabled].append(e)
         
        #get running ones
        for e in running:
            if e[0].lower().find(word)!=-1:
                final_dict[self.get_running].append(e)

        return final_dict

Note :

  • The method name should be "grep"
  • The method should use @func_module.findout decorator for

automatic result formatting.