Jun 272013
 

I’ve been building a “Stats Grabber” for one of the managers at work. The ServiceNow instance that I’m using only has the XML interface enabled at the moment so I’ll be using that.

This will just be a quick overview of what I’ve used to build this, won’t go into the details too much as each configuration will differ.
The stats that I needed were to be sorted by day, so I’ve defined a function that will return an array that each day will have.
I’ve cut down what I actually had but this gives you a good example.

function CreateArray() {
return array(
"req"=>"0",
"inc"=>"0",
"incMajor"=>"0",
"contacttypePhone"=>"0",
"contacttypeEmail"=>"0",
"contacttypeOther"=>"0",
"contacttypeAuto"=>"0",
"totalTickets"=>"0",
"reqResolved"=>"0",
"incResolved"=>"0",
"totalReqInc"=>"0",
"reqResBySD"=>"0",
"incResBySD"=>"0",
"totalResBySD"=>"0"
);
}

Next up is defining the URLs that are used to retrieve data.
The $instance variable will need to be defined.

// Request Queries
$requrl = "https://".$instance.".service-now.com/u_request_list.do?XML&sysparm_query=u_requestor!%3D9faaf5b90a0a7813005cc0d4347713bc%5Esys_created_onONDateRange%40javascript%3Ags.dateGenerate('".$_POST['startdate']."'%2C'start')%40javascript%3Ags.dateGenerate('".$_POST['enddate']."'%2C'end')";
$resolvedrequrl = "https://".$instance.".service-now.com/u_request_list.do?XML&sysparm_query=u_requestor!%3D9faaf5b90a0a7813005cc0d4347713bc%5Eu_resolvedONDateRange%40javascript%3Ags.dateGenerate('".$_POST['startdate']."'%2C'start')%40javascript%3Ags.dateGenerate('".$_POST['enddate']."'%2C'end')";

// Incident Queries
$incurl = "https://".$instance.".service-now.com/incident_list.do?XML&sysparm_query=sys_created_onONDateRange%40javascript%3Ags.dateGenerate('".$_POST['startdate']."'%2C'start')%40javascript%3Ags.dateGenerate('".$_POST['enddate']."'%2C'end')";
$resolvedincurl = "https://".$instance.".service-now.com/incident_list.do?XML&sysparm_query=u_resolvedONDateRange%40javascript%3Ags.dateGenerate('".$_POST['startdate']."'%2C'start')%40javascript%3Ags.dateGenerate('".$_POST['enddate']."'%2C'end')";

You may also notice the $_POST variables in the url, these will need to be passed to this script in the YYYY-MM-DD format. These will also be used later to construct the array for the days.

I’ve used CURL to retrieve the data, but there are a few different ways to do this
This snippet will create the $ch handle;

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $un .":". $pw);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

Next we’ll start getting the data.


// Get Requsts
curl_setopt($ch, CURLOPT_URL, $requrl);
$reqreturn = curl_exec($ch);

// Get Incidents
curl_setopt($ch, CURLOPT_URL, $incurl);
$increturn = curl_exec($ch);

// Get Resolved Requests
curl_setopt($ch, CURLOPT_URL, $resolvedrequrl);
$resreqreturn = curl_exec($ch);

// Get Resolved Incidents
curl_setopt($ch, CURLOPT_URL, $resolvedincurl);
$resincreturn = curl_exec($ch);

curl_close($ch);
// Curl End

I haven’t put in any error capturing but that is something that should be there to catch any errors when trying to retrieve the data.

Now to create the array that will contain all of our data.
As I wanted the data sorted by days, I’ve used a for loop with the start and end dates to create the array.

$DateArray = array();
if(isset($_POST['startdate']) && isset($_POST['enddate'])) {
$start = new DateTime($_POST['startdate']);
$end = new DateTime($_POST['enddate']);
$diff = $start->diff($end)->format("%a");
for($x = 0; $x < $diff+1; $x++) { $datestamp = date("Y-m-d",strtotime("+$x days",strtotime($start->format("Y-m-d"))));
$DateArray[$datestamp] = CreateArray();
}
}

Now we’ll start processing the data.
I’ll only post one of the four blocks for brevity as they’re esssentially the same with minor differences when it comes down to the data.
SimpleXML is used here to parse the xml output of ServiceNow

// Load Incidents XML
$xml = simplexml_load_string($increturn);
// Get Total Incidents
$incTotal = $xml->incident->count();
// Parse incidents for date
foreach($xml->incident as $item) {
$datestamp = date("Y-m-d",strtotime("+8 hours",strtotime($item->opened_at)));
$DateArray[$datestamp]["inc"]++;
$DateArray[$datestamp]["totalTickets"]++;
if($item->priority < 3) { $DateArray[$datestamp]["incMajor"]++; $totalMajorInc++; } switch($item->contact_type) {
case "Email":
$DateArray[$datestamp]["contacttypeEmail"]++;
break;
case "phone":
$DateArray[$datestamp]["contacttypePhone"]++;
break;
case "Auto Monitoring":
$DateArray[$datestamp]["contacttypeAuto"]++;
break;
default:
$DateArray[$datestamp]["contacttypeOther"]++;
break;
}
}

Once all four of those blocks have been executed, you now have the data all in a nice array.
You can then use a foreach loop on the DateArray array to get your data out

Share
Jun 202013
 

I recently decided to create a LiveCD to simplify downloading and flashing Raspberry Pi images.

I started off with the GParted ISO as that is already a small distribution, plus it has everything I needed for the PiParted distribution.
GParted comes in ISO form, so the first thing we need to do is mount the ISO file to get all the files that out of it. You’ll need to be root to mount the ISO file, or use sudo.

# mkdir -p ~/isodistro/iso
# mount -o loop gparted-live-0.16.1-1-i486.iso /mnt/iso
# cp -r /mnt/iso/* ~/isodistro/iso

You should see the following files inside

EFI EFI-imgs GParted-Live-Version GPL isolinux live syslinux utils

Inside the live directory, you will see these files

filesystem.packages filesystem.squashfs initrd.img memtest vmlinuz

The one we want is filesystem.squashfs, this file is what contains the main filesystem of the distribution.

As you can probably deduce from the file extension, this file is a squash fs file system. Which means that we can easily unsquash it.

# mkdir ~/isodistro/fs
# cp ~/isodistro/iso/live/filesystem.squashfs ~/isodistro/fs/
# cd ~/isodistro/fs
# unsquashfs filesystem.squashfs

This will create the squashfs-root directory within the fs directory, and if we have a look in there…

# ls squashfs-root/
bin dev etc home initrd.img lib media mnt opt proc root run sbin selinux srv sys tmp usr var vmlinuz

Tada ! We have the root filesystem of GParted.
The startup scripts are located within etc/gparted-live/gparted-live.d if you want to modify those.
Once the modifications have been made, you will need to pack it all back up, and repack the files into the ISO file.

mksquashfs ~/isodistro/fs/squashfs-root/* ~/isodistro/fs/filesystem.squashfs -comp xz
mv ~/isodistro/fs/filesystem.squashfs ~/isodistro/iso/live/
mkisofs -o youriso.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -J -R -V youriso-live ~/isodistro/iso

That will create the ISO file for you, and hopefully you should be able to boot your newly customised GParted distribution !

Share
Jun 142013
 

Not sure if this will be of use to anyone but I’ve decided to release it anyway…

I’ve split RSE2.4 into a directory and an image file.
The directory contains all the boot files that RSE needs to boot up, and the image file is meant to be dd’ed onto a USB stick or Hard drive.
As the image file is a partition, it should be dded onto a partition
e.g.

dd if=RSE2.4.HD.img of=/dev/sda1 bs=1M

The distro itself is the same as RSE 2.4 with the exception that it’s split over 2 devices.

You can download the zip file from here

SHA1SUM –
583ad4e16b0b56d686ddee84af471a67c5103b8f RSE2.4HD.zip
I updated RSE 2.4, so this is the new SHA1 sum
461d595a5eb646da97bd2d751f05d9dcfdf96204 RSE2.4.HD.img

Share
Jun 132013
 

**Updated version out here**

Hey everyone

I finally got around to getting Raspbian Server Edition updated.
This new version is based on Raspbian 2013-05-25
The end size was around 650MB, and I’ve stripped 295 packages from the default Raspbian install.

Download it from here

Sha1sum
b316b803df9f690c62c82c311460460f3dc0c7da RSE2.4.img
After I updated RSE2.4, this is the new SHA1 sum.
85a4d24055f6166b679dce5b3ccff70ddb67d559 RSE2.4.img


Please support the continued development of Raspbian Server Edition by donating !




Share