Skip to content

Instantly share code, notes, and snippets.

View cluther's full-sized avatar

Chet Luther cluther

View GitHub Profile
@cluther
cluther / change-datasource-interval
Last active August 29, 2015 14:13
change-datasource-interval
#!/usr/bin/env python
#
# This script allows a single datasource's cycletime (interval) to be
# changed.
#
# Example usage:
# change-cpu-interval --device=web-server-a --template=Device --datasource=cpu --interval=10
import sys
@cluther
cluther / telnet-7777-snippets.py
Last active August 29, 2015 14:13
Looking in the manhole for memory leaks..
import gc, sys
objs = []
for obj in gc.get_objects():
size = sys.getsizeof(obj, 0)
if size > 1024:
objs.append((obj, size))
objs.sort(key=lambda x: x[1], reverse=True)
from pprint import pprint
@cluther
cluther / __init__.py
Created October 23, 2014 18:44
Zenoss: Custom XML Export
# It is expected that the following code would be placed in the
# __init__.py of your ZenPack.
# lxml provides an API for building XML documents.
# http://lxml.de/tutorial.html#the-e-factory
from lxml import etree
from lxml.builder import E
# monkeypatch allows us to add a new method (myXML) to an existing
# object (ZentinelPortal a.k.a. /zport).
@cluther
cluther / __init__.py
Created October 21, 2014 14:25
Forking Zenoss metrics.
# This code goes into the __init__.py of a ZenPack. It patches the
# Products.ZenRRD.RRDUtil.RRDUtil.put() method. This allows for
# executing custom code for every RRD update that's made.
from Products.ZenUtils.Utils import monkeypatch
@monkeypatch('Products.ZenRRD.RRDUtil.RRDUtil')
def put(self, *args, **kwargs):
value = original(self, *args, **kwargs)
@cluther
cluther / component-add-menu.js
Created April 16, 2014 15:41
Zenoss: Add item to component-add-menu
(function(){
var router = Zenoss.remote.CustomRouter;
Ext.define('Zenoss.component.add.CustomThing',{
extend: 'Zenoss.SmartFormDialog',
constructor: function(config) {
config = config || {};
Ext.applyIf(config, {
height: 150,
@cluther
cluther / jmx_devices.py
Last active December 31, 2015 16:58
Print CSV of device and production state for all devices with at least one JMX datasource bound to the device or a component thereof.
def jmx_datasources(thing):
for template in thing.getRRDTemplates():
for ds in template.datasources():
if ds.enabled and ds.sourcetype == 'JMX':
return True
return False
for device in dmd.Devices.getSubDevicesGen():
if any(map(jmx_datasources, [device] + device.getMonitoredComponents())):
@cluther
cluther / example_output.txt
Last active February 5, 2016 20:13
Python Progress Logger
INFO:root:progress: 8 of 1000, elapsed=0:00:01, remaining=0:02:09
INFO:root:progress: 16 of 1000, elapsed=0:00:02, remaining=0:02:08
INFO:root:progress: 24 of 1000, elapsed=0:00:03, remaining=0:02:07
INFO:root:progress: 32 of 1000, elapsed=0:00:04, remaining=0:02:06
INFO:root:progress: 40 of 1000, elapsed=0:00:05, remaining=0:02:05
INFO:root:progress: 48 of 1000, elapsed=0:00:06, remaining=0:02:04
INFO:root:progress: 56 of 1000, elapsed=0:00:07, remaining=0:02:03
INFO:root:progress: 64 of 1000, elapsed=0:00:08, remaining=0:02:02
INFO:root:progress: 72 of 1000, elapsed=0:00:09, remaining=0:02:01
INFO:root:progress: 80 of 1000, elapsed=0:00:10, remaining=0:02:00
@cluther
cluther / allTransforms.py
Created September 24, 2013 21:29
Report of all Zenoss transforms.
#!/usr/bin/env zendmd
output = open('transforms.txt', 'w')
for ec in [dmd.Events] + dmd.Events.getSubOrganizers():
if ec.transform:
print >> output, "%s" % ec.getOrganizerName()
print >> output, "-"*len(ec.getOrganizerName())
print >> output, ec.transform
print >> output
for mapping in ec.instances():
if not mapping.transform: continue
@cluther
cluther / krb5_ccache.py
Created September 12, 2013 14:57
Python module for reading krb5 credential cache files.
#!/usr/bin/env python
##############################################################################
#
# Copyright (C) Zenoss, Inc. 2013, all rights reserved.
#
# This content is made available according to terms specified in
# License.zenoss under the directory where your Zenoss product is installed.
#
##############################################################################
@cluther
cluther / __init__.py
Created June 25, 2013 17:15
Add datapoint_count attribute to devices.
from Products.ZenUtils.Utils import monkeypatch
from ZODB.transact import transact
def get_datapoint_count(device):
'''
Return the total number of monitored datapoints on device.
'''
if not device.monitorDevice():
return 0