Exemplo n.º 1
0
    def save_return_payload(self, returnPayload):
        '''
        Process and save the data returned from the callhome server. This
        always includes versioning and crypto key changes, and may include
        other data to be processed by plugins to the IReturnPayloadProcessor
        interface.
        '''
        try:
            returnPayload = zlib.decompress(base64.urlsafe_b64decode(
                                                returnPayload))
            returnPayload = json.loads(returnPayload)
        except:
            logger.debug('Error decoding return payload from server')
            return

        if all(x in returnPayload for x in ('currentPublicKey',
                                            'revocationList')):
            # TODO: VERIFY revocation list, and apply
            newPubkey = returnPayload.get('currentPublicKey')
            if self.callHome.publicKey != newPubkey:
                self.callHome.publicKey = newPubkey

        if 'encrypted' in returnPayload:
            base64data = base64.urlsafe_b64decode(str(returnPayload.get(
                                                          'encrypted')))
            data = json.loads(decrypt(base64data, self.callHome.symmetricKey))

            if 'compliancereport' in data:
                data['compliancereport']['pdf'] = base64.urlsafe_b64decode(str(
                                              data['compliancereport']['pdf']))

            if 'latestVersion' in data:
                # Save the latest version, and send a
                # message if new version available
                self.dmd.lastVersionCheck = long(time.time())
                available = Version.parse('Zenoss ' + data['latestVersion'])
                if (getattr(self.dmd, 'availableVersion', '')
                        != available.short()):
                    self.dmd.availableVersion = available.short()
                    if self.dmd.About.getZenossVersion() < available:
                        try:
                            import socket
                            zep = getFacade('zep')
                            summary = ('A new version of Zenoss (%s)' +
                                       'has been released') % available.short()
                            zep.create(summary, 'Info', socket.getfqdn())
                        except ZepConnectionError:
                            logger.warning("ZEP not running - can't send " +
                                           "new version event")

            # Go through other data in the return payload, and process
            for name, utility in getUtilitiesFor(IReturnPayloadProcessor):
                if name in data:
                    utility.process(self.dmd, data[name])

        self.callHome.lastSuccess = long(time.time())
        self.chs.updateStat('lastSuccess', long(time.time()))
        return
Exemplo n.º 2
0
    def determineSteps(self):
        """
        Return a list of steps from self.allSteps that meet the criteria
        for this migrate run
        """
        # Ensure all steps have version numbers
        for step in self.allSteps:
            if step.version == -1:
                raise MigrationFailed("Migration %s does not set "
                                      "the version number" %
                                      step.__class__.__name__)

        # Level was specified
        if self.options.level is not None:
            levelVers = VersionBase.parse('Zenoss ' + self.options.level)
            steps = [s for s in self.allSteps
                        if s.version >= levelVers]

        # Step was specified
        elif self.options.steps:
            import re
            def matches(name):
                for step in self.options.steps:
                    if re.match('.*' + step + '.*', name):
                        return True
                return False
            steps = [s for s in self.allSteps if matches(s.name())]
            if not steps:
                log.error("No steps found that matched '%s'",
                           ', '.join(self.options.steps))
                log.error("Aborting")
                sys.exit(1)
            log.info("Will execute these steps: %s",
                     ', '.join(self.options.steps))

        else:
            currentDbVers = self._currentVersion()
            # The user did not specify steps to be run, so we run the default
            # steps.
            newDbVers = max(self.allSteps, key = lambda x:x.version).version
            if currentDbVers == newDbVers:
                # There are no steps newer than the current db version.
                # By default we rerun the steps for the current version.
                # If --newer was specified then we run nothing.
                if self.options.newer:
                    steps = []
                else:
                    steps = [s for s in self.allSteps
                                if s.version == currentDbVers]
            else:
                # There are steps newer than the current db version.
                # Run the newer steps.
                steps = [s for s in self.allSteps
                            if s.version > currentDbVers]

        return steps
Exemplo n.º 3
0
 def _currentVersion(self):
     """
     Return a VersionBase instance representing the version of the database.
     This also does some cleanup of dmd.version in case in is
     nonexistant, empty or set to a float value.
     """
     if not hasattr(self.dmd, 'version') or not self.dmd.version:
         self.dmd.version = 'Zenoss ' + VERSION
     if type(self.dmd.version) == type(1.0):
         self.dmd.version = "Zenoss 0.%f" % self.dmd.version
     v = VersionBase.parse(self.dmd.version)
     v.name = 'Zenoss'
     return v
Exemplo n.º 4
0
def version_check(dmd):
    params = urlencode({'product': dmd.getProductName()})
    try:
        httpreq = urllib2.urlopen(VERSION_CHECK_URL, params, _URL_TIMEOUT)
        returnPayload = json.loads(httpreq.read())
    except Exception as e:
        logger.warning('Error retrieving version from callhome server: %s', e)
    else:
        available = Version.parse('Zenoss ' + returnPayload['latest'])
        version = available.short()
        dmd.lastVersionCheck = long(time.time())
        if getattr(dmd, 'availableVersion', '') != version:
            dmd.availableVersion = version
Exemplo n.º 5
0
 def getEarliestAppropriateStepVersion(self, codeVers=None):
     """
     Return a Version instance that represents the earliest version
     of migrate step appropriate to run with this code base.
     The earliest version is basically the first sprint/alpha release
     for the current minor version.
     codeVers represents the current version of the code.  It exists
     for testing purposes and should usually not be passed in.
     """
     if codeVers is None:
         codeVers = VersionBase.parse('Zenoss %s' % VERSION)
     if codeVers.micro >= 70:
         # We are in a dev/beta release.  Anything back through the start
         # of this dev/beta cycle is appropriate.
         earliestAppropriate = Version(codeVers.major, codeVers.minor, 70)
     elif codeVers.minor > 0:
         # We are in a regular release that is not a  N.0 version.
         # Anything back through the previous dev/beta cycle is
         # appropriate
         earliestAppropriate = Version(codeVers.major, codeVers.minor-1, 70)
     else:
         # This is a X.0.Y release.  This is tough because we don't know
         # what the minor version was for the last release of version X-1.
         # We take the reasonable guess that the last version of X-1 that
         # we see migrate steps for was indeed the last minor release
         # of X-1.
         beforeThis = Version(codeVers.major)
         # self.allSteps is ordered by version, so just look back through
         # all steps for the first one that predates beforeThis.
         for s in reversed(self.allSteps):
             if s.version < beforeThis:
                 lastPrevious = s.version
                 break
         else:
             # We couldn't find any migrate step that predates codeVers.
             # Something is wrong, this should never happen.
             raise MigrationFailed('Unable to determine the appropriate '
                 'migrate script versions.')
         if lastPrevious.micro >= 70:
             earliestAppropriate = Version(lastPrevious.major,
                     lastPrevious.minor, 70)
         else:
             earliestAppropriate = Version(lastPrevious.major,
                     lastPrevious.minor-1, 70)
     return earliestAppropriate
# ZuulMessageFactory is the translation layer. You will see strings intended to
# been seen in the web interface wrapped in _t(). This is so that these strings
# can be automatically translated to other languages.
from Products.Zuul.utils import ZuulMessageFactory as _t

# In Zenoss 3 we mistakenly mapped TextLine to Zope's multi-line text
# equivalent and Text to Zope's single-line text equivalent. This was
# backwards so we flipped their meanings in Zenoss 4. The following block of
# code allows the ZenPack to work properly in Zenoss 3 and 4.

# Until backwards compatibility with Zenoss 3 is no longer desired for your
# ZenPack it is recommended that you use "SingleLineText" and "MultiLineText"
# instead of schema.TextLine or schema.Text.
from Products.ZenModel.ZVersion import VERSION as ZENOSS_VERSION
from Products.ZenUtils.Version import Version
if Version.parse('Zenoss %s' % ZENOSS_VERSION) >= Version.parse('Zenoss 4'):
    SingleLineText = schema.TextLine
    MultiLineText = schema.Text
else:
    SingleLineText = schema.Text
    MultiLineText = schema.TextLine


class IExampleComponentInfo(IComponentInfo):
    """
    Info adapter for ExampleComponent
    """

    devDescr = SingleLineText(title=_t(u"Device Description"),
                              readonly=True,
                              group='Details')
Exemplo n.º 7
0
 def __init__(self, *args, **kw):
     VersionBase.__init__(self, 'Zenoss', *args, **kw)
Exemplo n.º 8
0
 def getRabbitMQVersion(self):
     from Products.ZenUtils.qverify import ZenAmqp
     return Version.parse("RabbitMQ %s" % ZenAmqp().getVersion())
Exemplo n.º 9
0
 def getWmiVersion(self):
     from pysamba.version import VERSION
     return Version.parse('Wmi %s ' % VERSION)
Exemplo n.º 10
0
 def getPyNetSnmpVersion(self):
     from pynetsnmp.version import VERSION
     return Version.parse('PyNetSnmp %s ' % VERSION)
Exemplo n.º 11
0
 def getZenossVersionAndBuild(self):
     from Products.ZenModel.ZVersion import VERSION, BUILD_NUMBER
     return Version.parse("Zenoss %s %s" % (VERSION, BUILD_NUMBER))
Exemplo n.º 12
0
 def getZenossVersion(self):
     from Products.ZenModel.ZVersion import VERSION
     return Version.parse("Zenoss %s" % VERSION)
Exemplo n.º 13
0
 def __init__(self, *args, **kw):
     VersionBase.__init__(self, 'Zenoss', *args, **kw)
from Products.Zuul.form import schema
from Products.Zuul.interfaces.component import IComponentInfo
from Products.Zuul.interfaces.template import IRRDDataSourceInfo

# ZuulMessageFactory is the translation layer. You will see strings intended to
# been seen in the web interface wrapped in _t(). This is so that these strings
# can be automatically translated to other languages.
from Products.Zuul.utils import ZuulMessageFactory as _t

# In Zenoss 3 we mistakenly mapped TextLine to Zope's multi-line text
# equivalent and Text to Zope's single-line text equivalent. This was
# backwards so we flipped their meanings in Zenoss 4. The following block of
# code allows the ZenPack to work properly in Zenoss 3 and 4.

# Until backwards compatibility with Zenoss 3 is no longer desired for your
# ZenPack it is recommended that you use "SingleLineText" and "MultiLineText"
# instead of schema.TextLine or schema.Text.
from Products.ZenModel.ZVersion import VERSION as ZENOSS_VERSION
from Products.ZenUtils.Version import Version

if Version.parse("Zenoss %s" % ZENOSS_VERSION) >= Version.parse("Zenoss 4"):
    SingleLineText = schema.TextLine
    MultiLineText = schema.Text
else:
    SingleLineText = schema.Text
    MultiLineText = schema.TextLine


class IJuniperCardInfo(IComponentInfo):
    pass
Exemplo n.º 15
0
 def getNetSnmpVersion(self):
     from pynetsnmp.netsnmp import lib
     return Version.parse('NetSnmp %s ' % lib.netsnmp_get_version())
from Products.Zuul.form import schema
from Products.Zuul.interfaces.component import IComponentInfo
from Products.Zuul.utils import ZuulMessageFactory as _t


# In Zenoss 3 we mistakenly mapped TextLine to Zope's multi-line text
# equivalent and Text to Zope's single-line text equivalent. This was
# backwards so we flipped their meanings in Zenoss 4. The following block of
# code allows the ZenPack to work properly in Zenoss 3 and 4.

# Until backwards compatibility with Zenoss 3 is no longer desired for your
# ZenPack it is recommended that you use "SingleLineText" and "MultiLineText"
# instead of schema.TextLine or schema.Text.
from Products.ZenModel.ZVersion import VERSION as ZENOSS_VERSION
from Products.ZenUtils.Version import Version
if Version.parse('Zenoss %s' % ZENOSS_VERSION) >= Version.parse('Zenoss 4'):
    SingleLineText = schema.TextLine
    MultiLineText = schema.Text
else:
    SingleLineText = schema.Text
    MultiLineText = schema.TextLine


class IRabbitMQNodeInfo(IComponentInfo):
    vhostCount = schema.Int(title=_t(u"VHost Count"))
    exchangeCount = schema.Int(title=_t(u"Exchange Count"))
    queueCount = schema.Int(title=_t(u"Queue Count"))


class IRabbitMQVHostInfo(IComponentInfo):
    rabbitmq_node = schema.Entity(title=_t(u"Node"))
 def isVersion4(self):
     '''detect Zenoss version'''
     from Products.ZenUtils.Version import Version
     if Version.parse('Zenoss ' + ZENOSS_VERSION) >= Version.parse('Zenoss 4'): return True
     return False