Skip to content

Instantly share code, notes, and snippets.

View dougsyer's full-sized avatar

Doug Syer dougsyer

View GitHub Profile
@dougsyer
dougsyer / addMultiGraphReport.py
Created October 31, 2012 11:03 — forked from cluther/addMultiGraphReport.py
Programatically Build a Multi-Graph Report
#!/usr/bin/env python
import sys
import Globals
from Products.ZenUtils.ZenScriptBase import ZenScriptBase
# Check command line options.
if len(sys.argv) < 2:
print >> sys.stderr, "Usage: %s <device>" % sys.argv[0]
sys.exit(1)
# This script looks for, and fixes problems where zDeviceTemplates was
# set as a regular object attribute instead of through the acquisition
# mechanism.
from Acquisition import aq_base
for d in dmd.Devices.getSubDevices():
if hasattr(aq_base(d), 'zCollectorPlugins') and not d.hasProperty('zCollectorPlugins'):
print "%s has the problem." % d.id
templates = d.zCollectorPlugins
del(d.zCollectorPlugins)
d._setProperty('zCollectorPlugins', templates)
oldPlugin="zenoss.snmp.RouteMap"
newPlugin="IpRouteCSOB"
def replacePlugin(objs):
for obj in objs:
if not obj.hasProperty('zCollectorPlugins'): continue
if oldPlugin not in obj.zCollectorPlugins: continue
print "Replacing plugin for %s." % obj.id
obj.zCollectorPlugins = [
p for p in obj.zCollectorPlugins if p != oldPlugin ]
@dougsyer
dougsyer / wintranformeventlogv1.py
Created October 31, 2012 12:20
event dedup transform for win event logs v1
def smart_truncate(text, max_length=128, suffix='...'):
"""Returns a string of at most `max_length` characters, cutting
only at word-boundaries. If the string was truncated, `suffix`
will be appended.
"""
if len(text) > max_length:
pattern = r'^(.{0,%d}\S)\s.*' % (max_length-len(suffix)-1)
return re.sub(pattern, r'\1' + suffix, text)
else:
##############################################################################
#
# Copyright (C) Zenoss, Inc. 2012, all rights reserved.
#
# This content is made available according to terms specified in
# License.zenoss under the directory where your Zenoss product is installed.
#
##############################################################################
'''
from datetime import datetime
import time
#-------------------------------------------------
# conversions to strings
#-------------------------------------------------
# datetime object to string
dt_obj = datetime(2008, 11, 10, 17, 53, 59)
date_str = dt_obj.strftime("%Y-%m-%d %H:%M:%S")
print date_str
@dougsyer
dougsyer / gist:4b21043e4e0143a20534
Last active October 25, 2017 16:39
parsing zenoss trap snmp trap ciscoEnvMonTempStatusChangeNotif
# your modeller needs to strip off the "GREEN", yellow etc. or you can just change this to walk through the components
# and check to find the right now.
# i have updated envmonE to fix these but i need to publish the update to the public repo..
if device:
from Products.ZenUtils.Utils import prepId
import re
state_map = {
0: ('unknown', 3),
@dougsyer
dougsyer / Better linux os command map
Created May 21, 2015 22:13
Better linux os cmd modeller
ZenPacks/NWN/Events/modeler/plugins/NWN/cmd/centos_os_map.py
__version__ = '0.1'
from Products.DataCollector.plugins.CollectorPlugin import CommandPlugin
from Products.DataCollector.plugins.DataMaps import MultiArgs
import re
class centos_os_map(CommandPlugin):
"""
@dougsyer
dougsyer / zenoss-shell-functions
Created July 20, 2017 20:58 — forked from cluther/zenoss-shell-functions
Zenoss JSON API Examples (curl)
# This shell script is intended to be sourced into your shell. It adds
# Default Zenoss server settings.
[ -z "$ZENOSS_URL" ] && export ZENOSS_URL="http://localhost:8080"
[ -z "$ZENOSS_USERNAME" ] && export ZENOSS_USERNAME="admin"
[ -z "$ZENOSS_PASSWORD" ] && export ZENOSS_PASSWORD="zenoss"
# Generic call to make Zenoss JSON API calls easier on the shell.
zenoss_api () {
ROUTER_ENDPOINT=$1
@dougsyer
dougsyer / zenpop3.py
Last active September 21, 2017 18:39
Working on slight modifications to zenpop3
__doc__ = """zenpop3
Turn email messages obtained from POP3 accounts into events.
"""
import logging
import socket
import Globals