def test_implicit_dir_load_fails_when_unable_to_find_calling_dir(self):

        orig_get_calling_dir = utils.get_calling_dir
        utils.get_calling_dir = lambda: None

        with self.assertRaises(RuntimeError) as context_mgr:
            zenpacklib.load_yaml()

        self.assertIn('Unable to determine location',
                      str(context_mgr.exception))

        utils.get_calling_dir = orig_get_calling_dir
示例#2
0
    def test_multi_yaml(self):
        ''''''

        # reference yaml (all in one
        cfg_whole = zenpacklib.load_yaml(YAML_DOC)

        # reference yaml split across multiple files
        cfg_multi = zenpacklib.load_yaml([YAML_DOC_1, YAML_DOC_2, YAML_DOC_3, YAML_DOC_4, YAML_DOC_5, YAML_DOC_6])

        # dump both back to YAML
        whole_yaml = yaml.dump(cfg_whole.specparams, Dumper=Dumper)
        multi_yaml = yaml.dump(cfg_multi.specparams, Dumper=Dumper)

        compare_equals = compare_zenpackspecs(whole_yaml, multi_yaml)

        diff = ZenPack.get_yaml_diff(whole_yaml, multi_yaml)
        self.assertTrue(compare_equals,
                        'YAML merged dictionary test failed:\n{}'.format(diff))
示例#3
0
    def test_dir_load(self):
        ''''''
        # reference yaml (all in one
        cfg_whole = zenpacklib.load_yaml(YAML_WHOLE)

        # reference yaml split across multiple files
        fdir = '{}/data/yaml/test_dir_load'.format(
            os.path.abspath(os.path.dirname(__file__)))
        cfg_dir = zenpacklib.load_yaml(fdir)

        # dump both back to YAML
        whole_yaml = yaml.dump(cfg_whole.specparams, Dumper=Dumper)
        dir_yaml = yaml.dump(cfg_dir.specparams, Dumper=Dumper)

        compare_equals = utils.compare_zenpackspecs(whole_yaml, dir_yaml)

        diff = ZenPack.get_yaml_diff(whole_yaml, dir_yaml)
        self.assertTrue(compare_equals,
                        'YAML Multiple file test failed:\n{}'.format(diff))
示例#4
0
    def test_dir_load(self):
        ''''''
        # reference yaml (all in one
        cfg_whole = zenpacklib.load_yaml(YAML_WHOLE)

        # reference yaml split across multiple files
        fdir = '{}/data/yaml/test_dir_load'.format(
            os.path.abspath(os.path.dirname(__file__)))
        cfg_dir = zenpacklib.load_yaml(fdir)

        # dump both back to YAML
        whole_yaml = yaml.dump(cfg_whole.specparams, Dumper=Dumper)
        dir_yaml = yaml.dump(cfg_dir.specparams, Dumper=Dumper)

        compare_equals = compare_zenpackspecs(whole_yaml, dir_yaml)

        diff = ZenPack.get_yaml_diff(whole_yaml, dir_yaml)
        self.assertTrue(compare_equals,
                        'YAML Multiple file test failed:\n{}'.format(diff))
    def test_multi_yaml(self):
        ''''''

        # reference yaml (all in one
        cfg_whole = zenpacklib.load_yaml(YAML_DOC)

        # reference yaml split across multiple files
        cfg_multi = zenpacklib.load_yaml([
            YAML_DOC_1, YAML_DOC_2, YAML_DOC_3, YAML_DOC_4, YAML_DOC_5,
            YAML_DOC_6
        ])

        # dump both back to YAML
        whole_yaml = yaml.dump(cfg_whole.specparams, Dumper=Dumper)
        multi_yaml = yaml.dump(cfg_multi.specparams, Dumper=Dumper)

        compare_equals = compare_zenpackspecs(whole_yaml, multi_yaml)

        diff = ZenPack.get_yaml_diff(whole_yaml, multi_yaml)
        self.assertTrue(compare_equals,
                        'YAML merged dictionary test failed:\n{}'.format(diff))
示例#6
0
    def __init__(self, entry, verbose=False, level=20, specparams=False):
        """Create test harness using entry.

        entry can be any of the following:

        * Filename of single YAML file.
        * String containing YAML.
        * Already-built ZenPackSpec (CFG) object.

        """
        self.templates = None
        self.cfg = None
        self.yaml = None
        self.schema = None
        self.exported_yaml = None
        self.reloaded_yaml = None

        if isinstance(entry, ZenPackSpec):
            self.cfg = entry
        else:
            self.cfg = zenpacklib.load_yaml(
                entry,
                verbose=verbose,
                level=level)

            if not os.path.isdir(entry):
                self.yaml = load_yaml_single(entry, loader=OrderedLoader)

        if not self.yaml:
            yaml.dump(self.cfg, Dumper=Dumper)

        self.zp = self.cfg.zenpack_module
        self.schema = self.zp.schema
        self.build_cfg_obs()
        # create relations between objects
        self.build_relations()
        self.build_cfg_relations()

        self.exported_yaml = yaml.dump(self.cfg, Dumper=Dumper)
        self.reloaded_yaml = load_yaml_single(
            self.exported_yaml,
            loader=OrderedLoader)

        if specparams:
            self.export_specparams_yaml()
示例#7
0
    def get_config(self, yaml_doc):
        """Load a YAML document and return a dictionary describing it"""
        cfg = zenpacklib.load_yaml(yaml_doc,
                                   verbose=not self.disableLogging,
                                   level=10)
        cfg.test_setup()

        return {
            'cfg': cfg,
            'schema': cfg.zenpack_module.schema,
            'yaml_map': load_yaml_single(yaml_doc, loader=OrderedLoader),
            'yaml_dump': yaml.dump(cfg, Dumper=Dumper),
            'yaml_from_specparams': yaml.dump(cfg.specparams, Dumper=Dumper),
            'zenpack_module': cfg.zenpack_module,
            'zenpack_module_name': cfg.name,
            'zenpack': self.install_zenpack(cfg),
            'objects': ClassObjectHelper(self.dmd, cfg, self.build),
        }
import os
import logging
from ZenPacks.zenoss.ZenPackLib import zenpacklib

CFG = zenpacklib.load_yaml(
    [os.path.join(os.path.dirname(__file__), "zenpack.yaml")],
    verbose=False,
    level=30)
schema = CFG.zenpack_module.schema

from Products import Zuul
from Products.ZenUtils.Utils import monkeypatch
from Products.ZenUtils.zencatalog import reindex_catalog
from Products.Zuul.routers.report import ReportRouter

ZEN_ROLE = 'ZenReportUser'
LOG = logging.getLogger('Zen.ReportUserControl')


class ZenPack(schema.ZenPack):
    def install(self, app):
        super(ZenPack, self).install(app)
        self.installRole(app.zport, ZEN_ROLE)

        if not getattr(self, 'prevZenPackVersion', None):
            #update catalog to index new role
            globalCat = app.getPhysicalRoot().zport.global_catalog
            reindex_catalog(globalCat,
                            permissionsOnly=True,
                            printProgress=True,
                            commit=False)
# https://zenpack-sdk.zenoss.com/en/2.0.0/changes.html
from ZenPacks.zenoss.ZenPackLib import zenpacklib
CFG = zenpacklib.load_yaml()
schema = CFG.zenpack_module.schema
示例#10
0
Globals

ZENPACK_NAME = 'ZenPacks.zenoss.Microsoft.Windows'

DEVTYPE_NAME = 'Windows Server'
DEVTYPE_PROTOCOL = 'WinRM'
OLD_DEVTYPE_PROTOCOL = 'WMI'

from ZenPacks.zenoss.ZenPackLib import zenpacklib

zenpack_files = ('zenpack.yaml', 'event_classes.yaml', 'device_classes.yaml')
yaml_files = [
    os.path.join(os.path.dirname(__file__), yaml_file)
    for yaml_file in zenpack_files
]
CFG = zenpacklib.load_yaml(yaml_files)

schema = CFG.zenpack_module.schema

# Used by zenchkschema to validate relationship schema.
productNames = (
    'ClusterDevice',
    'ClusterResource',
    'ClusterService',
    'ClusterNode',
    'ClusterDisk',
    'ClusterNetwork',
    'ClusterInterface',
    'CPU',
    'Device',
    'Interface',
import os
from ZenPacks.zenoss.ZenPackLib import zenpacklib

CFG = zenpacklib.load_yaml([os.path.join(os.path.dirname(__file__), "zenpack.yaml")], verbose=False, level=30)
schema = CFG.zenpack_module.schema
    'classes.yaml', # contains new devices, components and their relationships
    'device_classes.yaml', # contains new device classes and their properties
)

# Main yaml directories
yamldirs = [
    'templates', # Contains individual yamls for each template
    'eventClasses', # Contains individual yamls for each eventClass
]

yamls = [
    os.path.join(dirname, yaml_file)
    for yaml_file in zenpack_files
    if os.path.exists(os.path.join(dirname, yaml_file))
]

# Parse yaml directories for yaml files
for yamldir in yamldirs:
    yamldir = os.path.join(dirname, yamldir)
    if not os.path.exists(yamldir):
        continue
    for name in os.listdir(yamldir):
        if name.endswith('.yaml'):
            yamls.append(os.path.join(yamldir, name))

CFG = zenpacklib.load_yaml(yamls, verbose=False, level=30)
schema = CFG.zenpack_module.schema

# Patches
#from ZenPacks.jstanley.Requests import patches
示例#13
0
#
##############################################################################

import Globals
import os.path
import logging
from ZenPacks.zenoss.ZenPackLib import zenpacklib

log = logging.getLogger("zen.NtpMonitor")

skinsDir = os.path.join(os.path.dirname(__file__), 'skins')
from Products.CMFCore.DirectoryView import registerDirectory
if os.path.isdir(skinsDir):
    registerDirectory(skinsDir, globals())


def onCollectorInstalled(ob, event):
    zpFriendly = 'NtpMonitor'
    errormsg = '{0} binary cannot be found on {1}. This is part of the nagios-plugins ' + \
               'dependency, and must be installed before {2} can function.'

    verifyBin = 'check_ntp'
    code, output = ob.executeCommand('zenbincheck %s' % verifyBin,
                                     'zenoss',
                                     needsZenHome=True)
    if code:
        log.warn(errormsg.format(verifyBin, ob.hostname, zpFriendly))


zenpacklib.load_yaml()
# import os
from ZenPacks.zenoss.ZenPackLib import zenpacklib

# CFG = zenpacklib.load_yaml([os.path.join(os.path.dirname(__file__), "zenpack.yaml")], verbose=False, level=30)
# schema = CFG.zenpack_module.schema

CFG = zenpacklib.load_yaml(verbose=False, level=20)
schema = CFG.zenpack_module.schema
log = logging.getLogger("zen.MicrosoftWindows")
# unused
Globals

ZENPACK_NAME = 'ZenPacks.zenoss.Microsoft.Windows'

DEVTYPE_NAME = 'Windows Server'
DEVTYPE_PROTOCOL = 'WinRM'
OLD_DEVTYPE_PROTOCOL = 'WMI'

from ZenPacks.zenoss.ZenPackLib import zenpacklib

zenpack_files = ('zenpack.yaml', 'event_classes.yaml', 'device_classes.yaml')
yaml_files = [os.path.join(os.path.dirname(__file__), yaml_file) for yaml_file in zenpack_files]
CFG = zenpacklib.load_yaml(yaml_files)

schema = CFG.zenpack_module.schema


# Used by zenchkschema to validate relationship schema.
productNames = (
    'ClusterDevice',
    'ClusterResource',
    'ClusterService',
    'ClusterNode',
    'ClusterDisk',
    'ClusterNetwork',
    'ClusterInterface',
    'CPU',
    'Device',
示例#16
0
##############################################################################
#
# Copyright (C) Zenoss, Inc. 2015, all rights reserved.
#
# This content is made available according to terms specified in
# License.zenoss under the directory where your Zenoss product is installed.
#
##############################################################################
import os
from ZenPacks.zenoss.ZenPackLib import zenpacklib

if 'ZPL_YAML_FILENAME' in os.environ:
    YAML = os.path.join(os.path.dirname(__file__), 'zenpack2.yaml')
else:
    YAML = os.path.join(os.path.dirname(__file__), 'zenpack.yaml')

CFG = zenpacklib.load_yaml(YAML)
示例#17
0
##############################################################################
#
# Copyright (C) Zenoss, Inc. 2014-2018, all rights reserved.
#
# This content is made available according to terms specified in
# License.zenoss under the directory where your Zenoss product is installed.
#
##############################################################################
"""Initialization for Docker.

All code in this module is executed anytime a Zenoss Python process starts.

"""

import os

from ZenPacks.zenoss.ZenPackLib import zenpacklib

CFG = zenpacklib.load_yaml([
    os.path.join(os.path.dirname(__file__), "zenpack.yaml"),
])

schema = CFG.zenpack_module.schema

# Patch last to avoid import recursion problems.
from . import patches  # noqa
 def afterSetUp(self):
     super(TestClassProxies, self).afterSetUp()
     try:
         zenpacklib.load_yaml(YAML)
     except Exception:
         self.fail(traceback.format_exc(limit=0))
#
# This content is made available according to terms specified in
# License.zenoss under the directory where your Zenoss product is installed.
#
##############################################################################

import Globals
import os.path
import logging
from ZenPacks.zenoss.ZenPackLib import zenpacklib

log = logging.getLogger("zen.NtpMonitor")

skinsDir = os.path.join(os.path.dirname(__file__), 'skins')
from Products.CMFCore.DirectoryView import registerDirectory
if os.path.isdir(skinsDir):
    registerDirectory(skinsDir, globals())

def onCollectorInstalled(ob, event):
    zpFriendly = 'NtpMonitor'
    errormsg = '{0} binary cannot be found on {1}. This is part of the nagios-plugins ' + \
               'dependency, and must be installed before {2} can function.'
    
    verifyBin = 'check_ntp'
    code, output = ob.executeCommand('zenbincheck %s' % verifyBin, 'zenoss', needsZenHome=True)
    if code:
        log.warn(errormsg.format(verifyBin, ob.hostname, zpFriendly))


zenpacklib.load_yaml()