[cisco-voip] Execute sql query via vmrest on CUC (or alternatative approach)?

Anthony Holloway avholloway+cisco-voip at gmail.com
Wed Mar 8 17:33:30 EST 2017


Actually, now that I think about it.  The User Data Dump utility can
probably achieve the exact same results, and requires no programming
knowledge at all.  I see a few different columns to pull from in the
utility like unread messages count and deleted items message count, but
nothing that just says total message count.  So, you'll either need to pull
all of those fields and add them up yourself, if just pull the mailbox size
in bytes and use that as your criteria.  Also, you can schedule the User
Data Dump to run automatically on a schedule too.

On Wed, Mar 8, 2017 at 4:28 PM Anthony Holloway <
avholloway+cisco-voip at gmail.com> wrote:

> I got a little too excited and wrote a starting Python script to get the
> Alias and Message counts and print them to stdout as a CSV format.  You'll
> need the requests module, which if you don't already have it, you should
> get it.  It's pretty nice for working with HTTP requests.  Also,
> disclaimer, I don't know how to properly handle the SSL cert here, so I'm
> basically ignoring it.  Not great security practice, I know.
>
> import requests
> from requests.packages.urllib3.exceptions import InsecureRequestWarning
> requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
>
> api_host = "cucpub.company.com"
> api_username = "cucadmin"
> api_password = "Password123!"
> users_per_page = 50
> current_page = 1
> url_users = "https://{0}/vmrest/users?rowsPerPage={1}&pageNumber={2}"
> url_user = "https://{0}/vmrest/users/{1}/mailboxattributes"
> headers = {'Accept': 'application/json'}
> response = requests.get(url_users.format(api_host, 0, current_page),
> auth=(api_username, api_password), verify=False, headers=headers)
> data = response.json()
> total_users = int(data['@total'])
> print "Getting message counts for a total of {0}
> users...\n".format(total_users)
>
> print "Alias,Message_Count"
> for page in range(total_users / users_per_page + 1):
> current_page = page + 1
> response = requests.get(url_users.format(api_host, users_per_page,
> current_page), auth=(api_username, api_password), verify=False,
> headers=headers)
> data = response.json()
> users = data['User']
> for user in users:
> obj = user['ObjectId']
> alias = user['Alias']
> response = requests.get(url_user.format(api_host, obj),
> auth=(api_username, api_password), verify=False, headers=headers)
> data = response.json()
> message_count = data['NumMessages']
> print "{0},{1}".format(alias, message_count)
>
> I'll leave it to you if you want to sort it in the Python script, or just
> sort it in Excel afterwards, since it's CSV output anyway.
>
> On Wed, Mar 8, 2017 at 4:08 PM Nick Barnett <nicksbarnett at gmail.com>
> wrote:
>
> Thanks Anthony and Brian.  I think i can make this work, especially after
> reading your firefox script and your non-code example... I think i can hack
> this together with another project I made in python and probably get it to
> work.
>
> Thanks,
> Nick
>
> On Wed, Mar 8, 2017 at 3:40 PM, Anthony Holloway <
> avholloway+cisco-voip at gmail.com> wrote:
>
> I don't think the CUC API has an arbitrary SQL execution method call like
> AXL does.
>
> Since the SQL query is effectively searching everyone's mailbox message
> counts, and then just filtering the output to you, you could write that
> same process using the CUPI API.
>
> Here's a high level program flow in no particular actual language:
>
> results = Array()
> response = HTTP GET https://<connection-server>/vmrest/users
> for each user in response.users:
> userobjectid = response.ObjectId
> alias = response.Alias
> response = HTTP GET https://<connection
> server>/vmrest/users/<userobjectid>/mailboxattributes
> count = response.NumMessages
> results.append(alias, count)
> results.sort(count, DESC)
> for each result in results:
> print result.alias, results.count
>
> Oh, and this is probably a good time to plug my Firefox GreaseMonkey User
> Script which shows you the breakdown of message counts per folder, and even
> let's you empty the deleted items.
>
> https://twitter.com/avholloway45633/status/828515885769953280
>
>
> On Wed, Mar 8, 2017 at 2:52 PM Nick Barnett <nicksbarnett at gmail.com>
> wrote:
>
> I found this SQL query
> <https://www.cisco.com/c/en/us/support/docs/unified-communications/unity-connection/118299-technote-cuc-00.html#anc8>
> to return a count of all message boxes in CUC. I modified it to return the
> top 10 by adding "FIRST 10" immediately after "select" on the first line:
>
> run cuc dbquery unitymbxdb1 select FIRST *10* alias as UserID, count (*)
> as messages \
>
> from vw_message, unitydirdb:vw_mailbox, unitydirdb:vw_user \
>
> where mailboxobjectid in \
>
> (select mailboxid from vw_mailbox where unitydirdb: vw_user.objectid =
> unitydirdb:vw_mailbox.userobjectid) \
>
> group by alias order by \
>
> messages desc
>
>
> This works, but it's not very "dev ops friendly." I think I'd have to use
> an expect script and code in my CLI password... which I really don't want
> to do.
>
>
> I looked through the VMREST kit for CUC 10.5 and I don't see anything like
> this. I can usually find my way around the AXL kit in CUCM but I frequently
> have issues finding what I need in the CUC VMREST calls.
>
>
> Is there a way to execute this specific query via VMREST to CUC? Is there
> a VMREST call already baked into CUC that will return similar information?
>
>
> Thanks,
>
> Nick
> _______________________________________________
> cisco-voip mailing list
> cisco-voip at puck.nether.net
> https://puck.nether.net/mailman/listinfo/cisco-voip
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://puck.nether.net/pipermail/cisco-voip/attachments/20170308/b6251bc1/attachment.html>


More information about the cisco-voip mailing list