Add Scroogle to your search area in Firefox 2.0 Install the 'Scroogle Scraper' search plugin.

Cloud computing is awesome until there is an error on booting and the SSH service doesn’t load for you. In that case, there isn’t an out-of-band console(ipmi/DRAC) to let you fix the issue like you’d have with a physical machine.

Recently, in response to the heartbleed/openssl vulnerability, we patched openssl. Then, after a reboot, we realized we couldn’t ssh into the instance, because something wasn’t right with sshd, so it didn’t load:

ssh: connect to host W.X.Y.Z port 22: Connection refused

The system logs from the ec2 management console showed ssh didn’t start because of a library conflict.

Starting sshd: /usr/sbin/sshd: /usr/local/firefox/libnssutil3.so: version `NSSUTIL_3.15' not found (required by /usr/lib64/libssl3.so) Cannot load /etc/httpd/modules/mod_ldap.so into server: /usr/local/firefox/libnssutil3.so: version `NSSUTIL_3.15' not found (required by /usr/lib64/libssl3.so)

Time to debug this by detaching and attaching that EBS root volume to another similar instance type:

  1. Create a similar instance “instance 2″ in the same availability zone
  2. Stop instance 1
  3. Take a snapshot of your root volume on instance 1 (for safety) and detach the root volume
  4. On the new instance, instance 2, attach the root volume as a secondary volume see: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-attaching-volume.html
  5. Mount the volume: $ sudo mount /dev/xvdf /mnt/secondaryvol/ (/dev/xvdf as specified it in management console)
  6. chroot your secondary volume: sudo chroot /mnt/secondaryvol/
  7. DEBUG! (in this case: mv /usr/local/firefox/libnssutil3.so /usr/local/firefox/libnss3.so.old; mv /usr/local/firefox/libnss3.so /usr/local/firefox/libnssutil3.so.old)
  8. type ‘exit’ to exit from chroot
  9. Umount the volume: $ sudo umount /mnt/secondaryvol/
  10. Detach the volume from instance 2
  11. Attach the volume back to instance 1 as /dev/sda1
  12. Start the instance

pingdom.com is great for monitoring websites and for exposing that data to your customers. But what if you have scheduled maintenance and want to pause the checking, say weekly? Pingdom fails you!*

Fortunately, they have an API!

<?php
	viewCheckStatus();
	echo "////////////////// PAUSE //////////////////////\r\n";
	pauseAll();
	viewCheckStatus();
	echo "////////////////// RESUME //////////////////////\r\n";
	resumeAll();
	viewCheckStatus();
	exit;
 
	function getCurlObject() {
    	$curl = curl_init();
    	curl_setopt($curl, CURLOPT_URL, "https://api.pingdom.com/api/2.0/checks");
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    	curl_setopt($curl, CURLOPT_USERPWD, "YOUR_EMAIL_HERE:PASSWORD_HERE");
    	curl_setopt($curl, CURLOPT_HTTPHEADER, array("App-Key: APP_KEY_GOES_HERE"));
    	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    	return $curl;
	}
 
	function viewCheckStatus() {
	$curl = getCurlObject();
    	curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
    	$response = getResponse( $curl );
    	$checksList = $response['checks'];
    	if(isset($checksList)){
			foreach ($checksList as $check) {
				print $check['name'] . " is " . $check['status'] . "\r\n";
			}
		}
		return;
	}
 
	function pauseAll() {
		$curl = getCurlObject();
		curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
		curl_setopt($curl, CURLOPT_POSTFIELDS, "paused=true");
		$response = getResponse( $curl );
		echo "\r\n" . $response['message'] . "\r\n";
		return;
	}
 
	function resumeAll(){
		$curl = getCurlObject();
		curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
		curl_setopt($curl, CURLOPT_POSTFIELDS, "paused=false");
		$response = getResponse( $curl );
		echo "\r\n" . $response['message'] . "\r\n";
		return;
	}
 
	function getResponse( $curl ) {
		$response = json_decode( curl_exec( $curl ),true );
		if( isset( $response['error'] ) ) {
			print "Error: " . $response['error']['errormessage'] . "\n";
			exit;
		}
		return $response;
	}
 
?>

**
*

Hi Ryan,

Thanks for contacting us!

At the moment [scheduled maintenance] isn't possible I'm afraid, the only type of maintenance windows we currently have are in the beta version of beep manager, and these only allow the suspension of alerts.

However, we will soon be introducing this feature to allow you to schedule maintenance windows.

In the meantime you can pause the checks before the maintenance windows and then start them up again after, this unmonitored time would not show up as downtime in the public status page or the reports. It can be automated with a bit of coding and using our API, documentation here:

https://www.pingdom.com/features/api/documentation/

Don't hesitate to contact us again if you have any further questions, comments or feedback for us.

Best regards,
Andreas Larsson
www.pingdom.com

* thx gthomas!

Recently I was in charge of a computer programming contest where we needed VM environments for each participant. I launched the ec2 console (https://console.aws.amazon.com/ec2), spun up a new amazon linux instance, configured it with a LAMP stack and vsftp, modified /etc/sshd/ssh_config to allow password ssh auth (for the config step), set apache to run as ec2-user and set ec2-user’s home directory to be /var/www/html. Also, I configured sudo to not require tty. I configured vsftp to use ports 20, 21 and 1024-1048. I added those ports to the launch-wizard-1 security group. Then I created an image(AMI) of that machine (ami-MYAMI).

Then I wrote this bash script which loops through a string array of usernames and spins up a new VM with a custom password for that user, displaying the user, password, and FQDN (tab delimited) for that instance on the screen:

user@local:~/amazon$ ssh -i passfile.pem ec2-user@FQDN.compute-1.amazonaws.com
[ec2-user@ip-INTERNAL_IP]$ cat create_instances.sh
#!/bin/bash
array=( entrant23 entrant24 entrant25 entrant26 entrant27 entrant28 entrant29 entrant30 entrant31 entrant32 entrant33 )
for i in "${array[@]}"
do
	INSTANCE_ID=`ec2-run-instances ami-MYAMI --instance-type c1.medium --group launch-wizard-1 -z us-east-1e -k keyname|grep 'INSTANCE'|awk '{print $2}'`
	SET_NAME=`id=$INSTANCE_ID;name=$i;ec2-create-tags $id --tag Name=$name`
	sleep 30s
	URL=`ec2-describe-instances | grep INSTANCE|grep $INSTANCE_ID|awk '{print $4}'`
	PASSWORD=`date +%s | sha256sum | base64 | head -c 8 ; echo`
	sleep 2m
	CHANGING_PASS=`ssh -i passfile.pem -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ec2-user@$URL "sudo echo 'ec2-user:$PASSWORD' | /usr/sbin/chpasswd"`
	FTP_IP=`ec2-describe-instances | grep INSTANCE|grep $INSTANCE_ID|awk '{print $14}'`
	CHANGING_FTP_IP=`ssh -i passfile.pem -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ec2-user@$URL "sudo /usr/bin/perl -p -i -e 's/IP_HERE/$FTP_IP/' /etc/vsftpd/vsftpd.conf"`
	RESTARTING_FTP=`ssh -i passfile.pem -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ec2-user@$URL "sudo /sbin/service vsftpd restart"`
	echo -e "$i\t$URL\t$PASSWORD"
done

The next step is to remove those pesky sleep statements and instead fire up all the instances at the start, and then create a wait loop checking statuses and sleeping, say 15 seconds. Once they come online, then run the post-launch steps (changing passwords, ftp settings, restarting ftp.)

One caveat– Amazon limits accounts to 20 VMs to start with. If you want more, you can request more, but that request could take up to 2 days to be approved. In my case, I used a personal account as well to created the instances we needed (40.)

LY3-enThanks to Quanta, the company no one has ever heard of, but which company makes all of Facebook’s servers and switches, for 6 or 7 grand, you can now get a 48 port Ethernet switch with 48 10GB ports, 8 of which are fiber. That’s nuts.

A friend dropped by last night with two Quanta T3040-LY3 and wanted to get them configured. I fired up the Byrd Super Lab, and with some cat6 cables I had laying around, I created an eight port MLAG connection between the two Quanta switches. Then I set up port channels for many of the 48 ports and then used LACP on the Linux side to create redundant paths for my test network.

photo(11)You should know there isn’t presently a lot of Google search results outside of retail establishments for Quanta hardware. So hopefully this post will be a good starting point for many people. I think you’ll find that the Quanta CLI is very similar to Cisco IOS. That said, there are some annoying differences. There is no enable mode, even though the manual refers to it and lets you set in and enable password. Also some commands cannot be undone by putting the word “no” in front of them like you can with Cisco. As well, it seems impossible to disable router rip or router IPv6. Hopefully someone from quanta can weigh in here and let us know what’s up.

That said here’s a sample of config for MLAG and LACP. Also I’ll provide a longer config for Quanta so that you can see how create VLANs on port channels running over MLAG.
mlag doc

Yes, I said MLAG. Some people call it MCLAG, but basically you contect two switch together with dedicated ports. Since they’re not Cisco switches, there’s no magical stacking cable included with these Quanta Servers.

It’s demeaning to refer to yourself as a dummy if you’re not, isn’t it? Here is the second session of PHP Programming for those non-dummies who want to get up to speed with this web programming language. Spoiler: you get to find a terrorist!

Other topics include FizzBuzz, Arrays, Functions, Objects and Forms. And Big-O notation. And, again, you get to find a terrorist.

Or, if you prefer, the PDF version of PHP Training Session Two

You’re not dumb, so why should the trainings be?

Here (below) is a quick introduction to PHP programming for the generally intelligent but uninformed would-be programmer. You’ll learn about conditionals, control structures(loops), operators and such. Originally, we planned on catching evil-doers (terrorists), but that will have to wait for session 2.

Or, if you prefer, the PDF version of PHP Training Session One

Imagine you have a set of cards. On one side of each card is a letter and on the reverse side of each is a number. You lay down four such cards:
A F 2 7

Your task is to determine which cards you must flip over in order to show that the following statement holds true: “If there is a vowel on one side of the card, there is an even number on the other side.”

This nagiosified Bash script sends a JSON payload to a webservice and parses the output for an expected string:

[root@server apitest]# ./webservice_check.sh
Usage: ./webservice_check.sh [API_NAME]
[root@server apitest]# ./webservice_check.sh service1
OK - service1 API working
[root@server apitest]# cat webservice_check.sh
#!/bin/bash
 
if [ $# -ne 1 ]; then
        echo "Usage: $0 [API_NAME]"
        exit
fi
E_SUCCESS="0"
E_CRITICAL="2"
case "$1" in
'service1')
API_NAME="service1"
URL="https://******.example.com/api"
JSONPAYLOAD='{"auth": {"type" : "basic","password": "******","username": "******"},"requestId" : 15,"method": {"name": "service1"}}'
COMMAND_STRING="curl -s -H \"Content-type: application/json; charset=UTF-8\" --data '$JSONPAYLOAD' $URL 2>/dev/null"
OUTPUT=`eval $COMMAND_STRING`
EXPECTED_RESULT="result"
;;
*)
echo "INVALID API Argument"
exit 1
esac
 
if grep -q "$EXPECTED_RESULT" <<< $OUTPUT; then
        echo "OK - $API_NAME API working"
        exit ${E_SUCCESS}
        else
        echo "CRITICAL - $API_NAME API not working"
        exit ${E_CRITICAL}
fi

Maybe you have the selenium firefox plugin and you’ve recorded some web tests and exported them in phpunit format and you’re running them against, say firefox. then you realize that launching a browser is not a fast thing to do. with firefox, you have to create a separate profile, disable plugins/update checks, and you’re severely limited to the number of simultaneous tests you can run.

then you hear of phantomjs, which encapsulates webkit (used in safari and chrome) and you decide it would be a LOT faster to use phantomjs instead of firefox. fortunately there is ghostdriver which is the glue for this. Here, below, I assume you’ve got selenium, phantomjs, ghostdriver, phpunit and PHPUnit_Selenium.

1. start selenium in hub mode: java -jar selenium-server-standalone-2.25.0.jar -role hub

2. register phantomjs with selenium: phantomjs –webdriver=8080 –webdriver-selenium-grid-hub=http://127.0.0.1:4444

3. use this code (which uses PHPUnit_Extensions_Selenium2TestCase not PHPUnit_Extensions_SeleniumTestCase):

require_once 'PHPUnit/Autoload.php';
 
class CDemoLoginTest extends PHPUnit_Extensions_Selenium2TestCase {
 
	protected function setUp() {
		$this->setBrowser( 'phantomjs' );
		$this->setBrowserUrl( 'http://www.example.com/' );
	}
 
  	public function testLogin() {  		
	    $cookies=$this->cookie();
	    $cookies->clear();
	    $this->url('http://www.example.com' );	    
	    $this->assertEquals( 'page title', $this->title() );
	    //echo($this->source());
	    $company_user = $this->byId('username');
	    $company_user->value('aUser' );
	    $password = $this->byId('password');
	    $password->value('aPassword' );	
	    $login=$this->byId('Login');
	    $login->click();    
	    $this->assertEquals( 'web portal', $this->title() );	    
	    $userLink=$this->byLinkText('logout' ); 
            $userLink->click();
	    $this->assertEquals( 'page title', $this->title() );
	}
}

4. run phpunit on it:

[root@server phantomtest]# phpunit --verbose CDemoLoginTest.class.php
PHPUnit 3.7.21 by Sebastian Bergmann.
 
.
 
Time: 4 seconds, Memory: 3.00Mb
 
OK (1 test, 3 assertions)
[root@server phantomtest]#

Note: PHPUnit_Extensions_Selenium2TestCase is newer and you can read about it here:

https://github.com/giorgiosironi/phpunit-selenium/blob/master/Tests/Selenium2TestCaseTest.php

https://github.com/sebastianbergmann/phpunit-selenium/blob/master/PHPUnit/Extensions/Selenium2TestCase.php

Screen Shot 2013-05-10 at 1.19.53 PMMaybe you’re giving a presentation and you’d like a quick “text your vote to this number” real-time poll. Maybe you don’t want to pay the commercial services out there and you have access to a php/mysql server. Here, below, below is some code to make your free poll become a reality. It’s based on this other open source text to vote system: https://github.com/rahims/Text-to-Vote and http://www.twilio.com/blog/2011/05/how-to-create-a-simple-sms-voting-system-using-php.html but instead of sqlite, my version uses MySQL:
handle_incoming_sms.php

<?php
	header('Content-type: text/xml');
	echo '<Response>';
	$phone_number = $_REQUEST['From'];
	$team_number = (int) $_REQUEST['Body'];
 
	if ( (strlen($phone_number) >= 10) && ($team_number > 0) )
	{
            $db=mysql_connect("localhost","user","pass");
            mysql_selectdb("database",$db);
            if (!$db)
            {
              echo "Failed to connect to MySQL: " . mysqli_connect_error();
            }
            $phone_number = mysql_real_escape_string($_REQUEST['From']);
            $team_number = mysql_real_escape_string($_REQUEST['Body']);
            $sql="insert into table set phone='".$phone_number."', team='".$team_number."'";
            $result=mysql_query($sql,$db);
            if (!$result) 
            {
   	        die('Invalid query: ' . mysql_error());
            }
	}
	else 
        {
		$response = 'Sorry, I didn\'t understand that. Text the team number to vote. For example, texting 1 will vote for Team 1.';
	}
 
	echo '<Sms>'.$response.'</Sms>';
	echo '</Response>';
?>

cat get_votes.php

<?php
     $db=mysql_connect("localhost","user","pass");
     mysql_selectdb("database",$db);
 
if (!$db)
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
 
$sql="SELECT COUNT(CASE WHEN team = '1' THEN 1 ELSE NULL END) AS team1,
COUNT(CASE WHEN team = '2' THEN 1 ELSE NULL END) AS team2,
COUNT(CASE WHEN team = '3' THEN 1 ELSE NULL END) AS team3
FROM table";
$result=mysql_query($sql,$db);
                if (!$result)
                {
                         die('Invalid query: ' . mysql_error());
                }
$row = mysql_fetch_assoc($result);
$team1= $row['team1'];
$team2= $row['team2'];
$team3= $row['team3'];
$votes=array((int)$team1, (int)$team2, (int)$team3);
	echo json_encode($votes);
?>

Next Page »

Send to a friend * Print this page * Join the club * Talk with my robot * Advertise here * Search this Site * Donate * Link to me


Web hosting by Utah Hub *  Powered by CreativeTap *  In association with Segomo
Unless otherwise noted, Copyright 2004-2013, Ryan Byrd. All Rights Reserved.
Ryan Byrd dot net -- probably the coolest site in Utah