The Assimilation Project  based on Assimilation version 1.1.7.1474836767
procsysdiscovery.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # vim: smartindent tabstop=4 shiftwidth=4 expandtab number
3 #
4 # This file is part of the Assimilation Project.
5 #
6 # Author: Alan Robertson <alanr@unix.sh>
7 # Copyright (C) 2013 - Assimilation Systems Limited
8 #
9 # Free support is available from the Assimilation Project community - http://assimproj.org
10 # Paid support is available from Assimilation Systems Limited - http://assimilationsystems.com
11 #
12 # The Assimilation software is free software: you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
16 #
17 # The Assimilation software is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with the Assimilation Project software. If not, see http://www.gnu.org/licenses/
24 #
25 #
26 
27 '''
28 Discovery Listener infrastructure
29 This is the base class for code that wants to hear about various
30 discovery packets as they arrive.
31 
32 More details are documented in the DiscoveryListener class
33 '''
34 #import sys
35 from systemnode import SystemNode
36 from AssimCclasses import pyConfigContext
37 from AssimCtypes import CONFIGNAME_TYPE, CONFIGNAME_INSTANCE
38 from cmaconfig import ConfigFile
39 
40 from discoverylistener import DiscoveryListener
41 
42 @SystemNode.add_json_processor
43 class ProcSysDiscovery(DiscoveryListener):
44  'Class for discovering the contents of /proc/sys'
45  prio = DiscoveryListener.PRI_OPTION
46  wantedpackets = ('OS', 'os')
47 
48  def processpkt(self, drone, _unused_srcaddr, jsonobj, discoverychanged):
49  "Send commands to gather discovery data from /proc/sys"
50  if not discoverychanged:
51  return
52  data = jsonobj['data'] # The data portion of the JSON message
53  osfield='operating-system'
54  if osfield not in data:
55  self.log.warning('OS name not found in %s' % str(data))
56  return
57  osname = data[osfield]
58  if osname.find('Linux') == -1 and osname.find('linux') == -1:
59  self.log.info('ProcSysDiscovery: OS name is not Linux: %s' % str(osname))
60  return
61 
62  params = ConfigFile.agent_params(self.config, 'discovery', 'proc_sys', drone.designation)
63  params['parameters'] = pyConfigContext({'ASSIM_discoverdir': '/proc/sys' })
64  params[CONFIGNAME_TYPE] = 'proc_sys'
65  params[CONFIGNAME_INSTANCE] = '_auto_proc_sys'
66 
67  # Request discovery of checksums of all the binaries talking (tcp) over the network
68  if self.debug:
69  self.log.debug('REQUESTING /proc/sys DISCOVERY')
70  drone.request_discovery((params,))
def processpkt(self, drone, _unused_srcaddr, jsonobj, discoverychanged)