Tuesday, September 4, 2012

automating netscaler with soap


I recently had to script some citrix netscaler stuff (around using the running config to create graph trees in cacti and collectd with ecostats front end)

to use the soap interface you have to make a soap request to login, then reuse the returned cookie to authenticate the other requests like this.

I use this wget to login

wget   -O- --cookies=on --keep-session-cookies  --save-cookies cookies.txt  --post-file=login.xml --header="Content-Type: application/soap+xml"  http://yourNSip/soap  

and this to get the details of vservers etc.

  wget  -O- --load-cookies cookies.txt  --post-file=getlbserver.xml --header="Content-Type: application/soap+xml"  http://yourNSip/soap  

where the post-files contain the soap requests

you can pipe into xmllint to tidy up the output if you want

 | xmllint --format --encode utf-8 –

cat login.xml

<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:NSConfig" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:header>
   <soapenv:body>
      <urn:login soapenv:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/">
         <username xsi:type="xsd:string">username</username>
         <password xsi:type="xsd:string">thisisnotmypassword</password>
      </urn:login>
   </soapenv:body>
</soapenv:header></soapenv:envelope>

cat getlbserver.xml

<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:NSConfig" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:header>
   <soapenv:body>
      <urn:getlbvserver soapenv:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/">
      </urn:getlbvserver>
   </soapenv:body>
</soapenv:header></soapenv:envelope>

reference data  http://support.citrix.com/article/CTX117503
and http://support.citrix.com/proddocs/topic/netscaler-api-map-93/ns-api-query-config-con.html

Sunday, June 24, 2012

Sky remote code for LG

A friend got an LG 47LM660t and couldn't get his sky HD remote to work the tv volume. After some google searching the code isn't know, so I thought I'd post it.

Follow the usual sky instructions and use code 1293 . This still looked like it didn't work for him, but it appears the remote was confused. the up down arrows around the select button did the volume, not the volume control !

I had seen this before fortunately,

Press TV Key

Hold down select and press 2 until the remote's LED flashes twice (if it only flashes once or remains on steady I'm afraid your remote does not support this feature).

Press Sky key and it should work

if it doesn't try select and press 1 instead of 2.

Tuesday, March 20, 2012

rsync with CDN and purge

I recently had to setup a new CDN for, using Edgecast,

They support rsync for content and also have an API, so I started with cron'd full rsync, but this was taking too long, so I moved to rsync only recently changed files, and used the output to do a flush of the cache for updated files. Edgecast provide a really good CDN solution, and also provide EU based rsync endpoints for getting your logs and pushing your content




#!/bin/sh
set -e
rm -rf /tmp/rsync.ec.out
rm -rf /tmp/changedfiles

#move to directory so path names are good in outputs
cd /opt/www/htdocs/

#find recently modified files
find . -mmin -120 > /tmp/changedfiles

#run rsync for these changed files, only changing existing files and logging output
/usr/bin/rsync --itemize-changes -az --existing -e "ssh -i /home/rsync/.ssh/my_special_id_rsa -p8022 -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no" --files-from=/tmp/changedfiles /opt/www/htdocs/ user@domain@rsync.ams.edgecastcdn.net:/content/mysubdir/ > /tmp/rsync.ec.out

#loop through output so we can purge changed files
for filetopurge in `grep "^<f" /tmp/rsync.ec.out | cut -d " " -f2`; do
if [ -f $filetopurge ]
then
echo '<MediaContentPurge xmlns="
http://www.whitecdn.com/schemas/apiservices/"><MediaPath>http://wpc.use-cust-number-here.edgecastcdn.net/use-cust-number-here/mysubdir/'$filetopurge'</MediaPath><MediaType>3</MediaType></MediaContentPurge>' | curl --insecure -X PUT -H "Authorization: TOK:use-your-token-here" -H 'Content-type: text/xml' -d @- https://api.edgecast.com/v2/mcc/customers/use-cust-number-here/edge/purge
echo -e "\nPurging ${filetopurge}"
fi
done

#now run rsync for remainder of files
/usr/bin/rsync -azv --ignore-existing -e "ssh -i /home/rsync/.ssh/my_special_id_rsa -p8022 -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no" --files-from=/tmp/changedfiles /opt/www/htdocs/ user@domain@rsync.ams.edgecastcdn.net:/content/mysubdir/