Zensendevent in Zenoss 4.2.3

From Zenoss Wiki
This is the approved revision of this page, as well as being the most recent.
Jump to: navigation, search

The zensendevent utility is used to generate test events. You can get usage with zensendevent --help.

$ zensendevent --help
Usage: zensendevent [options] summary

  -h, --help            show this help message and exit
  -d DEVICE, --device=DEVICE
                        device from which this event is sent, default:
                        Ip from which this event was sent, default:
  -y EVENTKEY, --eventkey=EVENTKEY
                        eventKey to be used, default:
  -p COMPONENT, --component=COMPONENT
                        component from which this event is sent, default: ''
                        eventClassKey for this event, default: ''
  -s SEVERITY, --severity=SEVERITY
                        severity of this event: Critical, Error, Warn, Info,
                        Debug, Clear
  -c EVENTCLASS, --eventclass=EVENTCLASS
                        event class for this event, default: ''
  --monitor=MONITOR     monitor from which this event came
  --port=PORT           xmlrpc server port, default: 8081
  --server=SERVER       xmlrpc server, default: localhost
  --auth=AUTH           xmlrpc server auth, default: admin:zenoss
  -o OTHER, --other=OTHER
                        Specify other event_field=value arguments. Can be
                        specified more than once.
                        Import events from XML file.
  -v                    Show the event data sent to Zenoss.

Note the auth parameter with a default of admin:zenoss.

New with Zenoss 4.2.3 the autodeploy script will generate a robust password for the admin user for various elements of Zenoss. This includes accessing zenhub which is where zensendevent sends events. The hubpasswd is stored in $ZENHOME/etc/hubpasswd in the format <user>:<password> and replaces the old default of admin:zenoss. If you don't specify the correct authentication parameters, zensendevent will fail with an authentication error.

Either you can specify the user and new password explicitly on the auth parameter or, if you have scripts that embed zensendevent, or you simply use it a lot, it would be better to have zensendevent try and get the authentication parameters automatically.

I have developed a version of zensendevent which does this.

Modified zensendevent

zensendevent can be found in $ZENHOME/bin. I append the changed lines below.

134 parser.add_option('-v', dest="show_event", default=False,
135     action='store_true',
136     help="Show the event data sent to Zenoss.")
139 opts, args = parser.parse_args()
141 # Hack by JC to get hubpasswd authentication into auth option
142 # Password is held in $ZENHOME/etc/hubpasswd in (almost) correct format <user>:<password> \n
144 import os
145 # if auth is the default
146 if opts.auth == 'admin:zenoss':
147   zenhome=os.environ['ZENHOME']
148   # Try to access $ZENHOME/etc/hubpasswd and strip trailing newline
149   try:
150     pwfile=open(os.path.join(zenhome, 'etc', 'hubpasswd'), 'r')
151     opts.auth=pwfile.read().rstrip()
152     pwfile.close()
153     print 'Extracting necessary user:password automatically \n'
154   # If this fails then fall back to default and print message
155   except:
156     print 'Attempt to detect hubpasswd failed \n'
158 # End of JC hack
160 url = "http://%s@%s:%s" % (opts.auth, opts.server, opts.port)
161 serv = ServerProxy(url)

Bulbgraph.png Note: Ensure that you backup $ZENHOME/bin/zensendevent before attempting these change

Bulbgraph.png Note: zensendevent is a standalone utility that could be used elsewhere than the Zenoss server. This changed version will fail if not on the Zenoss server as $ZENHOME/etc/hubpasswd will not be found.

Bulbgraph.png Note: The zenqdump utility to show information about contents of RabbitMQ queues, has a similar problem.