Sep 7, 2008 6:10 PM
How to reset IP using zendmd?
-
Like (0)
Hello,
Been searching answer for this for quite a while and nobody seem to answer it within this forum so I think I should create new topic for this.
Can anyone enlighten me on how to reset device IP using zendmd or event transform or in any other programmatically way instead of using Web UI (Device -> More -> Manage IP). I will need to do this for <100 servers, so looking for another way than the UI way apparently..
Thanks in advance.
_______________________________________________
zenoss-users mailing list
zenoss-users@zenoss.org ([email]zenoss-users@zenoss.org[/email])
http://lists.zenoss.org/mailman/listinfo/zenoss-users
Sorry for typo on my first post. Instead of More -> Manage IP, the
post should say Manage -> Reset IP.
Thanks for quick reply. And your scripts kind of promising too. But
then, I was looking for ways to emulate the UI way to reset the IP
to get new one from DNS, but within command line or python scripts,
since the devices I am monitoring now use dynamic line which get
their dynamic IP from ISP. The device currently run ddclient which
will updating the IP changes to the dyndns.org server name that I
have created before.
Every time the dynamic IP changes, the device send event 'ip <ip
number> has down' to Zenoss server, and the way I always did to
clear that event out is through UI, which is:
1- Go to device page
2- Click Manage -> Reset IP
3- Leave blank to use DNS (which will get new IP from DNS)
4- Go to Device Events & Acknowledge/push the red alert events to
history
5- Push changes
6- Remodel the device.
But for < 100 servers run on dynamic IP and increasing, I wish there
are far more practical way to do that..
Not really good in Python, so struggling a bit to get this thing done.
I bet the keys is within the zendmd, So first thing on my list to
emulate in zendmd is the 2nd and 3rd step shown above which will be
Click Manage -> Reset IP & Leave blank to use DNS. How to emulate
that in zendmd..
Will play a lot more with zendmd, but I welcome those who can help
with this problem.
Thanks Scott, will study your code and perhaps tweak little bit here
and there if you wont mind.
The pointer that you gave me really helpful. Following this link:
http://www.zenoss.com/community/docs/zenoss-api-docs/2.2/, I now
manage to identify the steps that should be taken within zendmd.
Testing with one device first:
Manual UI way:
1- Go to device page
2- Click Manage -> Reset IP & Leave blank to use DNS (which will get
new IP from DNS)
3- Go to Device Events & Acknowledge/push the red alert events to
history
4- Clear Heartbeats
5- Push changes
6- Remodel the device.
Zendmd way:
1- find('clf*')
Returns:
<Device at /zport/dmd/Devices/Server/Dumas/devices/
clfantasy.dyndns.org>
d = find('clf*')
2- d.getManageIp()
'xx.xx.2.183' <--- OLD IP
d.setManageIp()
'xx.xxx.48.189' <--- NEW IP from DNS
commit()
3- I dont see what class should I used to push red alert event down
to history, perhaps the Zen Master could enlighten me on this one.
[Wink]
4- Clear Heartbeats
_______________________________________________
5- Push changes
d.pushConfig()
6- Remodel the device.
d.collectDevice()
Refreshing my zenoss page, I can see the the IP has change,
everything green coming back again EXCEPT the red alert event still
inside the Event tab since I haven't do anything about that one
inside the zendmd.
Thanks Chet!! Really appreciate it.. If only you can tell me what
class to use to push the red event down to history... that will make
much more cool! I start to like zendmd now..
Okay, with my limited knowledge in Python, I will now try to write
some script for mass-resetting devices DNS.. [Idea]
#!/usr/bin/env python
import Globals
from Products.ZenUtils.ZenScriptBase import ZenScriptBase
from transaction import commit
dmd = ZenScriptBase(connect=True).dmd
for d in dmd.Systems.getSubDevices():
evids = [ e.evid for e in dmd.ZenEventManager.getEventListME(d) ]
if (len(evids) !=0):
d.setManageIp()
commit()
dmd.ZenEventManager.manage_ackEvents(evids)
dmd.ZenEventManager.manage_deleteEvents(evids)
commit()
dmd.ZenEventManager.manage_clearHeartbeats()
commit()
d.checkRelations(repair=True)
commit()
d.pushConfig()
commit()
d.collectDevice()
commit()
for d in dmd.Devices.getSubDevices(): <-- this refer to whole group
d.setManageIp()
commit()
Be aware that this will blank out the IP address for devices that
can't be resolved with DNS. You may want to do the following
afterwards to find any devices with a blank manageIp so that you can
get them added to DNS.
pprint([ d.id for d in dmd.Devices.getSubDevices() if d.manageIp ==
"" ])
Refer to Zenoss Dev Guide for example on looking for specific device.
zenoss@zenoss$ ./massdnsresetter.py
Traceback (most recent call last):
File "./massdnsresetter.py", line 17, in ?
dmd.ZenEventManager.manage_ackEvents(evids)
File "/usr/local/zenoss/Products/ZenEvents/EventManagerBase.py", line 1581, in manage_ackEvents
self.manage_setEventStates(1 , evids, REQUEST=request)
File "/usr/local/zenoss/Products/ZenEvents/EventManagerBase.py", line 1610, in manage_setEventStates
messaging.IMessageSender(self).sendToBrowser(
File "usr/local/zenoss/lib/python/zope/interface/interface.py", line 682, in __call__
TypeError: ('Could not adapt', <MySqlEventManager at /zport/dmd/ZenEventManager>, <InterfaceClass Products.ZenWidgets.interfaces.IMessageSender>)
i really need to query on a given ip, check to ensure that its the current managedip for that device and if so set a new mgmt ip
also the devices are not in dns
any ideas?
great !!! men!
Consider the former ip may not that quitely be assigned to some other machine that allows ping and snmp.
(even worse like that, some specific http service should come into consideration.)
and since the event related to dynamic ip change should have the eventclass of "/Status/Ping".
I made some modification base on your script, as follow, which I think makes more sense:
#!/usr/bin/env python
import Globals
from Products.ZenUtils.ZenScriptBase import ZenScriptBase
from transaction import commit
dmd = ZenScriptBase(connect=True).dmd
for d in dmd.Devices.getSubDevices():
## if you have them grouped
#for d in getattr(dmd.Groups, 'Group name').getSubDevices():
for e in dmd.ZenEventManager.getEventListME(d):
if e.eventClass == "/Status/Ping" or e.eventClass == "/Status/Snmp":
d.setManageIp()
commit()
dmd.ZenEventManager.manage_ackEvents(e.evid)
dmd.ZenEventManager.manage_deleteEvents(e.evid)
commit()
dmd.ZenEventManager.manage_clearHeartbeats()
commit()
d.checkRelations(repair=True)
commit()
d.pushConfig()
commit()
d.collectDevice()
commit()
Follow Us On Twitter »
|
Latest from the Zenoss Blog » | Community | Products | Services Resources | Customers Partners | About Us | ||
Copyright © 2005-2011 Zenoss, Inc.
|
||||||||