TechColumnist Storage Information Blog

16Jul/101

ISY Python Script for controlling media lights via xbmc

Here is a simple python script to use the REST code in the ISY (http://universal-devices.com) to control devices that are linked. I'm designing this script to be used inside a script for xbmc. here's the first part of it. I recommend using scenes for the devicedim, deviceoff, and deviceon array, however you can use the individual devices as well in the array.


import urllib2
import urllib
import sys

devicedim = ['41941']
deviceoff = ['48839']
deviceon = ['62270']
username = 'admin'
password = 'admin'

topurl = 'http://isy'
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, topurl, username, password)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)

if sys.argv[1] == 'playing':
	for devicex in deviceoff:
		theurl = 'http://isy/rest/nodes/' + devicex + '/cmd/DOF'
		#normalize the URL
		theurl = urllib.quote(theurl, safe="%/:=&?~#+!$,;'@()*[]")
		print (theurl)
		pagehandle = urllib2.urlopen(theurl)
	for devicex in devicedim:
		theurl = 'http://isy/rest/nodes/' + devicex + '/cmd/DON/64'
		#normalize the URL
		theurl = urllib.quote(theurl, safe="%/:=&?~#+!$,;'@()*[]")
		print (theurl)
		pagehandle = urllib2.urlopen(theurl)
elif sys.argv[1] == 'stopped':
	for devicex in deviceon:
		print (devicex)
		theurl = 'http://isy/rest/nodes/' + devicex + '/cmd/DON'
		#normalize the URL
		theurl = urllib.quote(theurl, safe="%/:=&?~#+!$,;'@()*[]")
		print (theurl)
		pagehandle = urllib2.urlopen(theurl)
else:
	print 'no state given'

Usage:

isy-medialights.py playing|stopped
Tagged as: , , 1 Comment
7Jul/100

Schedule a URL into Maintenance Mode

Found a nice article about how to script a URL (or web application) into maintenance mode. This was a little bit of a challenge to find so I'm reposting it to hopefully get some more attention. I've also posted the modified version of the script that allows for multiple watcher hosts.

param($rootMS,$urlName,$minutes,$comment,$reason)
Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorVariable errSnapin;

Set-Location "OperationsManagerMonitoring::" -ErrorVariable errSnapin;
new-managementGroupConnection -ConnectionString:$rootMS -ErrorVariable errSnapin;
set-location $rootMS -ErrorVariable errSnapin;

$URLWatcher = (Get-MonitoringClass -name Microsoft.SystemCenter.WebApplication.Perspective) | Get-MonitoringObject | where {$_.DisplayName -eq $urlName}

$startTime = [System.DateTime]::Now
$endTime = $startTime.AddMinutes($minutes)

"Putting URL into maintenance mode"
foreach ($name in $URLWatcher) {
New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$name -comment:$comment -Reason:$reason }

Usage:

C:WINDOWSsystem32WindowsPowerShellv1.0powershell.exe URLMaintenanceModeV4.ps1 -rootMS: `SCOMRMS1′ -urlName: ‘MSN Website Checker’ -minutes:45 -comment: ‘My Comment’ -reason: ‘PlannedOther’

http://www.scom2k7.com/schedule-a-into-url-maintenance-mode/

Tagged as: , No Comments
4Jul/100

First iphone 4 post

Testing out the new phone. Been a while since the last post. Looks pretty neat to be able to write a post while mobile.

Tagged as: , No Comments