コード例 #1
0
ファイル: TaskManager.py プロジェクト: OpenTouch/night-watch
 def _loadTasks(self):
         tasks_location = getNwConfiguration().tasks_location
         
         tasks_files = []
         try:
             for f in os.listdir(tasks_location):
                 if os.path.isfile(os.path.join(tasks_location,f)) and isYamlFile(f):
                     tasks_files.append(f)
         except Exception, e:
             getLogger(__name__).critical('The directory ' + tasks_location + ' is not reachable', exc_info=True)
             exit(-1)
コード例 #2
0
ファイル: TaskManager.py プロジェクト: OpenTouch/night-watch
    def _loadTasks(self):
        tasks_location = getNwConfiguration().tasks_location

        tasks_files = []
        try:
            for f in os.listdir(tasks_location):
                if os.path.isfile(os.path.join(tasks_location,
                                               f)) and isYamlFile(f):
                    tasks_files.append(f)
        except Exception, e:
            getLogger(__name__).critical('The directory ' + tasks_location +
                                         ' is not reachable',
                                         exc_info=True)
            exit(-1)
コード例 #3
0
def _loadProviderConfig(provider_name):
    # If the provider's config is not already loaded, check if a config exist for this provider and load it
    if not _providerConfig.has_key(provider_name):
        # if the folder which will contain the log file don't exists, create it
        path_config_file = os.path.join(getNwConfiguration().providers_location, provider_name + '.yml')
        getLogger(__name__).debug('Try to load config file for provider "' + provider_name + '" from location ' + path_config_file)
        if os.path.exists(path_config_file):
            _providerConfig[provider_name] = loadYamlFile(path_config_file)
            getLogger(__name__).info('Config file for provider "' + provider_name + '" successfully loaded from location ' + path_config_file)
        else:
            # No config file available for this Provider, store None so that the ProvidersManager does not try to load again the config file for this Provider
            _providerConfig[provider_name] = None
            getLogger(__name__).info('No config file found for provider "' + provider_name + '"')
    else:
        getLogger(__name__).debug('Config file for provider "' + provider_name + '" is already loaded')
    return _providerConfig[provider_name]
コード例 #4
0
def _loadActionConfig(action_name):
    # If the Action's config is not already loaded, check if a config exist for this Action and load it
    if not _actionConfig.has_key(action_name):
        # build the path of the Action to load by concatenating the actions_location config section from main config file with the {name of the action to load}.yml
        path_config_file = os.path.join(getNwConfiguration().actions_location,
                                        action_name + '.yml')
        getLogger(__name__).debug('Try to load config file for action "' +
                                  action_name + '" from location ' +
                                  path_config_file)
        if os.path.exists(path_config_file):
            _actionConfig[action_name] = loadYamlFile(path_config_file)
            getLogger(__name__).info('Config file for action "' + action_name +
                                     '" successfully loaded from location ' +
                                     path_config_file)
        else:
            # No config file available for this Action, store None so that the ActionsManager does not try to load again the config file for this Action
            _actionConfig[action_name] = None
            getLogger(__name__).info('No config file found for action "' +
                                     action_name + '"')
    else:
        getLogger(__name__).debug('Config file for action "' + action_name +
                                  '" is already loaded')
    return _actionConfig[action_name]
コード例 #5
0
ファイル: test-ping.py プロジェクト: OpenTouch/night-watch
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from nw.providers.Ping import Ping
from nw.core.NwConfiguration import getNwConfiguration
from nw.core import Log

# Read the Night Watch main config file from /etc/night-watch/night-watch.yml
config_file = '/etc/night-watch/night-watch.yml'

# Load the NW config file (required so that the Provider can load its config file)
config = getNwConfiguration()
config.read(config_file)
# Reconfigure the logger now that we loaded the logging config from NW config file
Log.reconfigure(config.logging)

#===============================================================================
# Test returned code
#===============================================================================
config = {'ping_addr': 'www.google.com', 'count': 5, 'timeout': 15}
# call ping provider
pingProvider = Ping(config)
ping_status = pingProvider.process()
print "Test returned code: " + str(ping_status)

#===============================================================================
# Test ping response
コード例 #6
0
ファイル: test-ping.py プロジェクト: OpenTouch/night-watch
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from nw.providers.Ping import Ping
from nw.core.NwConfiguration import getNwConfiguration
from nw.core import Log


# Read the Night Watch main config file from /etc/night-watch/night-watch.yml
config_file = '/etc/night-watch/night-watch.yml'

# Load the NW config file (required so that the Provider can load its config file)
config = getNwConfiguration()
config.read(config_file)
# Reconfigure the logger now that we loaded the logging config from NW config file
Log.reconfigure(config.logging)

#===============================================================================
# Test returned code
#===============================================================================
config = {
          'ping_addr': 'www.google.com',
          'count': 5,
          'timeout': 15
         }
# call ping provider
pingProvider = Ping(config)
ping_status = pingProvider.process()