Ascend Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
(ASCEND) python 'aview' utility enhanced
Howdt folks,
We installed the MAX Utilities which included "maxstatus" a program in
Python to query the MAX with SNMP for usernames, IP's, etc.
I'm probably way out of date, and there's some new version that's been
released- but I went ahead and rewrote some parts of it.
It's only useful if you have the MIBs properly installed, and the python
language interpreter installed.
Here's the source, and I don't really know python, so the source is very
evil.
Be sure to set the IP address and SNMP read community name for what your
MAX is. This is pretty similar to what that "loop" web utility does.
Note that python is extremely picky about whitespace, so if my mailer
doesn't eat this to bits, it should run fine. (It's a drop in replacement
for the 'maxstatus' program)
----------------------- CUT HERE ---------------
#!/usr/local/bin/python
import sys, posix, os
os.environ['MIBFILE'] = '/usr/local/lib/ascend.mib'
import snmp, snmpmisc, string
ascend = snmp.open("1.1.1.1", "public" )
ray = [ 0 ]
def ascend_get(str):
tmp = '.iso.org.dod.internet.private.enterprises.ascend.' + str
try:
return ascend.get(tmp)
except:
return (None, 'Invalid SNMP OID' + ' ' + str, 0)
def ascend_get_other(str):
tmp = str
try:
return ascend.get(tmp)
except:
return (None, 'Invalid SNMP OID' + ' ' + str, 0)
def build_callref():
loop = 1
found = 0
while (loop < 121):
zzz, chk, zzz2 = ascend_get("sessionStatusGroup.sessionStatusTable.sessionStatusEntry.ssnStatusCallReferenceNum." + `loop`)
chk2 = string.atoi(chk)
ray.append(chk2)
loop = loop+1
return (1)
def find_callref(int):
loop = 1
found = 0
while (loop < 121):
if (int == ray[loop]):
found = loop
loop = loop+1
return (found)
def my_time(int):
days = 0
hours = 0
minutes = 0
secs = 0
days, temp = divmod(int, 62400)
hours, temp2 = divmod(temp, 3600)
minutes, secs = divmod(temp2, 60)
timeon = `days` + "d " + `hours` + ":" + `minutes` + ":" + `secs`
return timeon
systime=ascend.get("system.sysUpTime.0")
uptime=string.atoi(systime[1])
print " Line Modem Time Uploaded/"
print "User Speed IP Address :Chan :Port On Type /Download"
print "-------------------------------------------------------------------------------"
u = 1
i = 1
v = 1
build_callref()
while(i < 137):
valid=ascend_get("callStatusGroup.callStatusTable.callStatusEntry.callStatusValidFlag." + `i`)
flag = string.atoi(valid[1])
if (flag > 1):
z, sesidx, z2=ascend_get("callStatusGroup.callStatusTable.callStatusEntry.callStatusCallReferenceNum." + `i`)
callref = string.atoi(sesidx)
if (callref >= 1):
booga = find_callref(callref)
a, uname, a2=ascend_get("sessionStatusGroup.sessionStatusTable.sessionStatusEntry.ssnStatusUserName." + `booga`)
b, speed, b2=ascend_get("callStatusGroup.callStatusTable.callStatusEntry.callStatusDataRate." + `i`)
b, line, b2=ascend_get("callStatusGroup.callStatusTable.callStatusEntry.callStatusSlotNumber." + `i`)
b, linetwo, b2=ascend_get("callStatusGroup.callStatusTable.callStatusEntry.callStatusSlotLineNumber." + `i`)
linenum=string.atoi(line);
linetwonum=string.atoi(linetwo);
if (linenum == 1):
line_test = linetwonum
else:
line_test = 3
b, channel, b2=ascend_get("callStatusGroup.callStatusTable.callStatusEntry.callStatusSlotChannelNumber." + `i`)
b, modemslot, b2=ascend_get("callStatusGroup.callStatusTable.callStatusEntry.callStatusModemSlotNumber." + `i`)
b, modemport, b2=ascend_get("callStatusGroup.callStatusTable.callStatusEntry.callStatusModemOnSlot." + `i`)
b, istr, b2=ascend_get("callStatusGroup.callStatusTable.callStatusEntry.callStatusIfIndex." + `i`)
ifindex=string.atoi(istr)
b, inbytes, b2=ascend_get_other("interfaces.ifTable.ifEntry.ifInOctets." + `ifindex`)
b, outbytes, b2=ascend_get_other("interfaces.ifTable.ifEntry.ifOutOctets." + `ifindex`)
c, ip, c2=ascend_get("sessionStatusGroup.sessionStatusTable.sessionStatusEntry.ssnStatusUserIPAddress." + `booga`)
d=ascend_get("callStatusGroup.callStatusTable.callStatusEntry.callStatusStartingTimeStamp." + `i`)
tstamp=string.atoi(d[1])
duration = (uptime / 100) - tstamp
time = my_time(duration)
e=ascend_get("sessionStatusGroup.sessionStatusTable.sessionStatusEntry.ssnStatusCurrentService." + `booga`)
service=string.atoi(e[1])
if (service == 3):
type = 'PPP'
elif (service == 11):
type = 'Telnet'
elif (service == 14):
type = 'Terminal Server'
elif (service == 5):
type = 'MultiChannel PPP'
elif (service == 15):
type = 'MultiLink PPP'
else:
type = 'unknown'
if (uname != '\"\"'):
print "%-8s %-5s %-15s %1d:%-2s %1s:%-2s %-11s %-4s %7s / %8s" % (uname, speed, ip, line_test, channel, modemslot, modemport, time, type, inbytes, outbytes)
u = u + 1
i = i+1
print "-----------------------------------------------------------------------------"
u = u-1
print "Total Users: %d" % (u)
------------------------- CUT HERE ------------------------
-Will Pierce
System Administrator
Dreamscape Online, LLC.
willp@dreamscape.com
++ Ascend Users Mailing List ++
To unsubscribe: send unsubscribe to ascend-users-request@bungi.com
To get FAQ'd: <http://www.shore.net/~dreaming/ascend-faq>
or <ftp://ftp.shore.net/members/dreaming/ascend-faq.txt>