Scalability Blog http://www.robertsindall.co.uk/blog .net, the cloud, databases and other technology for highly scalable systems Sat, 31 Aug 2013 16:14:28 +0000 en-US hourly 1 http://wordpress.org/?v=3.6 How to migrate an existing DNS zone file to Amazon Route 53 http://www.robertsindall.co.uk/blog/how-to-migrate-an-existing-dns-zone-file-to-amazon-route-53/ http://www.robertsindall.co.uk/blog/how-to-migrate-an-existing-dns-zone-file-to-amazon-route-53/#comments Sat, 31 Aug 2013 16:08:19 +0000 Robert http://www.robertsindall.co.uk/blog/?p=1422 Importing an existing zone file to Amazon Route 53 has historically been less than straight forward. In this example we will import an existing zone file into Route 53 using a free command line tool called cli53.

What Amazon Route 53?

Amazon Route 53 is a highly available and scalable Domain Name System (DNS) web service. Route 53 is designed to be fast, easy to use, and cost-effective. It answers DNS queries with low latency by using a global network of DNS servers. Queries for your domain are automatically routed to the nearest DNS server, and thus answered with the best possible performance.

Install cli53 dependencies

Log into an Amazon Linux instance using PuTTY and type:

sudo yum -y install python-pip*
sudo yum -y install python-boto
sudo easy_install pip

Install cli53

sudo pip install cli53

Configure cli53 security access

touch ~/.boto
vi ~/.boto

Now let’s add this to the file and add your key and access key

[Credentials]
 aws_access_key_id = [your AWS ID]
 aws_secret_access_key = [your AWS key]

Preparing your zone file into Route 53

First, get a copy of your latest zone file, in this case we are going to use: example.com

Now add a new line to the top of the file and add this line – remember the trailing dot

$ORIGIN example.com.

So you should get a file like this

$ORIGIN example.com.     
$TTL 1h                  ; default expiration time of all resource records without their own TTL value
example.com.  IN  SOA  ns.example.com. username.example.com. (
              2007120710 ; serial number of this zone file
              1d         ; slave refresh (1 day)
              2h         ; slave retry time in case of a problem (2 hours)
              4w         ; slave expiration time (4 weeks)
              1h         ; maximum caching time in case of failed lookups (1 hour)
              )
example.com.  NS    ns                    ; ns.example.com is a nameserver for example.com
example.com.  NS    ns.somewhere.example. ; ns.somewhere.example is a backup nameserver for example.com
example.com.  MX    10 mail.example.com.  ; mail.example.com is the mailserver for example.com
@             MX    20 mail2.example.com. ; equivalent to above line, "@" represents zone origin
@             MX    50 mail3              ; equivalent to above line, but using a relative host name
example.com.  A     192.0.2.1             ; IPv4 address for example.com
              AAAA  2001:db8:10::1        ; IPv6 address for example.com
ns            A     192.0.2.2             ; IPv4 address for ns.example.com
              AAAA  2001:db8:10::2        ; IPv6 address for ns.example.com
www           CNAME example.com.          ; www.example.com is an alias for example.com
wwwtest       CNAME www                   ; wwwtest.example.com is another alias for www.example.com
mail          A     192.0.2.3             ; IPv4 address for mail.example.com,
                                          ;  any MX record host must be an address record
                                          ; as explained in RFC 2181 (section 10.3)
mail2         A     192.0.2.4             ; IPv4 address for mail2.example.com
mail3         A     192.0.2.5             ; IPv4 address for mail3.example.com

Now lets save this zone file on to the server using vi

vi example.com

Now add zone file and save – including $ORIGIN example.com.

Importing your zone file into Route 53

If you’ve not already added the zone to route 53, run this command

cli53 create example.com

Now your can import your zone file into Route 53

cli53 import example.com --file example.com --replace --wait

Use this command to check your zone file has been imported into Route 53

cli53 info example.com

Further reading

]]>
http://www.robertsindall.co.uk/blog/how-to-migrate-an-existing-dns-zone-file-to-amazon-route-53/feed/ 0
How to configure MongoDB to log to PaperTrailApp on Amazon Linux http://www.robertsindall.co.uk/blog/how-to-configure-mongodb-to-log-to-papertrailapp-on-amazon-linux/ http://www.robertsindall.co.uk/blog/how-to-configure-mongodb-to-log-to-papertrailapp-on-amazon-linux/#comments Wed, 24 Apr 2013 00:01:14 +0000 Robert http://www.robertsindall.co.uk/blog/?p=1201 MongoDB to log to PaperTrailApp]]> In this post we will configure MongoDB to log to PaperTrailApp

What is MongoDB?

MongoDB is a document database that provides high performance, high availability, and easy scalability.

What is PaperTrailApp

PaperTrailApp is a hosted log management service for servers, apps, and cloud services

You will need to create an account with PaperTrail

Settings up MongoDB to log to PaperTrailApp

Access the MongoDB instances using SSH and run this command

sudo yum -y install gcc ruby-devel rubygems gcc-c++ openssl-devel
sudo gem install remote_syslog
sudo gem install eventmachine
sudo vi /etc/log_files.yml

Update the file with the below configuration

files:
  - /var/log/mongo/mongod.log
destination:
  host: logs.papertrailapp.com
  port: XXXXX   # Papertrail dest port (default: 514)
exclude_patterns: # exclude noise generated by over zealous C# driver prior to v1.8 connection recycling
  - connection accepted
  - end connection

Where XXXXX is the port number provided to you by PaperTrailApp

Start the logging service

Configure auto start of logging service

wget https://raw.github.com/papertrail/remote_syslog/master/examples/remote_syslog.init.d

The file needs editing to force logging to use the full hostname and change the startup priority.

By default PaperTrailApp will reduce a hostname of

mongodb.eu-west-1a.XXX_XXX_XXX_XXX

to just

mongodb

This means all the logs from all MongoDB instances will appear to come from the same source

Apr 24 01:13:09 mongodb mongod.log:  Wed Apr 24 00:13:09.188 [conn505716] query

So add this argument to the end of the process start command

--hostname $HOSTNAME

to add the hostname to the log

...
start(){
    echo -n $"Starting $prog: "

    unset HOME MAIL USER USERNAME
    $prog -c $config --pid-file $pid_file "$EXTRAOPTIONS" --hostname $HOSTNAME
...

So that a log entry look like this

// example log entry
Apr 24 01:13:09 mongodb.eu-west-1b.xxx_xxx_xxx_xxx mongod.log:  Wed Apr 24 00:13:09.188 [conn505716] query ...

The default start up priority occurs before that of

/etc/init.d/cloud-init-user-scripts 

at time of writing this was

chkconfig: 2345 99 99

In order for hostname changes to have completed, alter the start up priority from 90 to 99 (i.e. start remote_syslog after cloud-init-user-scripts):

chkconfig: 345 99 5

And edit cloud-init-user-scripts to guarantee that it runs before remote_syslog

sudo vi /etc/init.d/cloud-init-user-scripts
# chkconfig: 345 98 98

Save and run the following to realise chkconfig priorty edits.

chkconfig cloud-init-user-scripts resetpriorities
sudo mv remote_syslog.init.d /etc/init.d/remote_syslog
sudo chown root:root /etc/init.d/remote_syslog
sudo chmod u+x /etc/init.d/remote_syslog
sudo chkconfig --add remote_syslog
sudo service remote_syslog start

Configure rsyslog

Configure General syslog Messages

sudo vi /etc/rsyslog.conf 

Add this as the first non-comment line

# Required to force logs to use their full hostname
$PreserveFQDN on

Add this to the very end of the file:

# VoucherCloud Paper Trail config
*.*                                         @logs.papertrailapp.com:XXXXX

Where XXXXX is the port provided by PaperTrailApp

Save and quit vi

Restart rsyslog

sudo service rsyslog restart

Further Reading

Original instructions are below, but the steps that are ultimately run are very different so this link is just for reference

]]>
http://www.robertsindall.co.uk/blog/how-to-configure-mongodb-to-log-to-papertrailapp-on-amazon-linux/feed/ 0
Using Fiddler as proxy in .NET app.config http://www.robertsindall.co.uk/blog/using-fiddler-as-proxy-in-net-app-config/ http://www.robertsindall.co.uk/blog/using-fiddler-as-proxy-in-net-app-config/#comments Tue, 23 Apr 2013 08:18:36 +0000 Robert http://www.robertsindall.co.uk/blog/?p=1136 Fiddler as a local proxy for a .net app, it is simple, yet very handy for debugging.]]> In this post we will setup Fiddler as a local proxy for a .net app, it is simple, yet very handy for debugging.

What is Fiddler?

Fiddler is a Web Debugging Proxy which logs all HTTP(S) traffic between your computer and the Internet. Fiddler allows you to inspect traffic, set breakpoints, and “fiddle” with incoming or outgoing data.

Download Fiddler

You need to download Fiddler and install it.

Setting your .NET app to use Fiddler

Add this section on configuration to your app.config


  
   
  
 

Once Fiddler is running it will proxy all traffic for the app.

]]>
http://www.robertsindall.co.uk/blog/using-fiddler-as-proxy-in-net-app-config/feed/ 0
How to use Amazon Web Services Auto Scaling Groups http://www.robertsindall.co.uk/blog/how-to-use-amazons-auto-scaling-groups/ http://www.robertsindall.co.uk/blog/how-to-use-amazons-auto-scaling-groups/#comments Mon, 22 Apr 2013 10:14:25 +0000 Robert http://www.robertsindall.co.uk/blog/?p=1266 Auto Scaling Groups]]> This post we will cover all the commands to create and managed Amazons Auto Scaling Groups

What is an Auto Scaling Group?

Auto Scaling allows you to scale your Amazon EC2 capacity up or down automatically according to conditions you define. With Auto Scaling, you can ensure that the number of Amazon EC2 instances you’re using increases seamlessly during demand spikes to maintain performance, and decreases automatically during demand lulls to minimize costs.

You will need to set up Amazon Auto Scaling Groups Command Line Tools on Windows

Now you will need an Amazon Machine Image (AMI)

What is an Amazon Machine Image (AMI)?

An Amazon Machine Image (AMI) is a special type of pre-configured operating system and virtual application software which is used to create a virtual machine within the Amazon Elastic Compute Cloud (EC2). It serves as the basic unit of deployment for services delivered using EC2.

Let’s imagine you have an AMI: ami-xxxxxx

Before you can create an Auto Scaling Group you need a Launch Configuration

What is a Launch Configuration?

A Launch Configuration defines the AMI to be used, the size of the EC2 instances to be used, the security group the instances will live in and the private key used to decrypt the password in Windows or for gaining access via SSH

You will need to set up Amazon Auto Scaling Groups Command Line Tools on Windows before you can start

How to create a Launch Configuration?
// create launch config
as-create-launch-config my-launch-config-1 --image-id ami-xxxxxx --region eu-west-1 --instance-type m1.small --group my-securitygroup-sg --key myKey
How to check the launch configuration has been created?
// check launch config has been created
as-describe-launch-configs --headers --region eu-west-1  --max-records 50

or check just your launch config has been create

// check your launch config has been created
as-describe-launch-configs my-launch-config-1 --headers --region eu-west-1  --max-records 50
How to delete a launch configuration?
// delete launch config
as-delete-launch-config my-launch-config-1 --region eu-west-1
How to creating an Auto Scaling Group?
// create auto scaling group
as-create-auto-scaling-group my-auto-scaling-group --region eu-west-1 --launch-configuration my-launch-config-1 --availability-zones eu-west-1a eu-west-1b eu-west-1c --min-size 3 --max-size 3 --desired-capacity 3 --default-cooldown 5 --grace-period 5 --tag "k=Name, v=my-server, p=true" --tag "k=enabled, v=true, p=true"
How to check the Auto Scaling Group has been created?
// check auto scaling group has been created
as-describe-auto-scaling-groups --headers --region eu-west-1
How to add or update the Auto Scaling Group tags?

Add or update the Name tag

// add or update the tag
as-create-or-update-tags --tag "id=my-auto-scaling-group, t=auto-scaling-group, k=Name, v=my-server, p=true" --region eu-west-1

Add or update a custom ROLE tag

// add or update the tag
as-create-or-update-tags --tag "id=my-auto-scaling-group, t=auto-scaling-group, k=ROLE, v=production, p=true" --region eu-west-1

Add or update a custom ALLOWED_IPS tag

// add or update tag
as-create-or-update-tags --tag "id=my-auto-scaling-group, t=auto-scaling-group, k=ALLOWED_IPS, v=XXX.XXX.XXX.XXX, p=true" --region eu-west-1
How to scale up the Auto Scaling Group?

This would scale your group of instances up to 6 and set a max of 12

// scale up
as-update-auto-scaling-group my-auto-scaling-group --region eu-west-1 --min-size 6 --max-size 12 --desired-capacity 6
How to scale down the Auto Scaling Group?

This would scale your group of instances up to 3 and set a max of 6

// scale down
as-update-auto-scaling-group my-auto-scaling-group --region eu-west-1 --min-size 3 --max-size 6 --desired-capacity 3
How to set zero instances in the Auto Scaling Group?

This would remove all instances, but keep the auto scaling group configuration ready for use in the future

// with zero instances
as-update-auto-scaling-group my-auto-scaling-group --desired-capacity 0 --max-size 0 --min-size 0 --region eu-west-1
How to delete an Auto Scaling Group?
// delete auto scaling group
as-delete-auto-scaling-group my-auto-scaling-group --region eu-west-1
How to get the Auto Scaling Groups latest activities?

This is handy for trouble shooting problems with your Auto Scaling Group

// to get latest actions
as-describe-scaling-activities --auto-scaling-group my-auto-scaling-group --region eu-west-1

How to update the Auto Scaling Group Configuration

This command lets you change auto scaling group configuration, zones, the min, max and desired number of instances

// with many options
as-update-auto-scaling-group my-auto-scaling-group --launch-configuration my-launch-config-2 --availability-zones eu-west-1a eu-west-1b eu-west-1c --desired-capacity 3 --max-size 3 --min-size 3 --region eu-west-1
How to change the Auto Scaling Group’s Launch Configuration

This will set a new launch configuration for the auto scaling group

// with new launch config
as-update-auto-scaling-group my-auto-scaling-group --launch-configuration my-launch-config-2 --region eu-west-1

Further Reading

]]>
http://www.robertsindall.co.uk/blog/how-to-use-amazons-auto-scaling-groups/feed/ 2
How to set up Amazon Auto Scaling Groups Command Line Tools on Windows http://www.robertsindall.co.uk/blog/how-to-set-up-amazon-auto-scaling-group-command-line-tools-on-windows/ http://www.robertsindall.co.uk/blog/how-to-set-up-amazon-auto-scaling-group-command-line-tools-on-windows/#comments Sun, 21 Apr 2013 23:47:26 +0000 Robert http://www.robertsindall.co.uk/blog/?p=1367 Amazon Auto Scaling Group Command Line Tools on Windows.]]> In this post we will set up Amazon Auto Scaling Group Command Line Tools on Windows.

What is an Auto Scaling Group?

Auto Scaling allows you to scale your Amazon EC2 capacity up or down automatically according to conditions you define. With Auto Scaling, you can ensure that the number of Amazon EC2 instances you’re using increases seamlessly during demand spikes to maintain performance, and decreases automatically during demand lulls to minimize costs.

Download Auto Scaling Command Line Tool

You will need to download the Auto Scaling Command Line Tool

Now unzip the package to this folder on you Windows machine

C:\aws\AutoScaling-1.0.61.2

At the time of writing I am using v1.0.61.2

Configuring the Auto Scaling Group Command Line Tool

Next you need to setup all the server variables

How to set the AWS_AUTO_SCALING_HOME server variable
set AWS_AUTO_SCALING_HOME="C:\aws\AutoScaling-1.0.61.2"
How to set the JAVA_HOME server variable
set JAVA_HOME="C:\Program Files (x86)\Java\jre7"

Or use these instructions Setting JAVA_HOME Variable in Windows

How to set the EC2_PRIVATE_KEY server variable
set EC2_PRIVATE_KEY="C:\AWS\ec2-private-key.pem"
How to set the EC2_CERT server variable
set EC2_CERT="C:\AWS\ec2-cert.pem"

Alternatively you can set all these system variables by follow these steps

  1. Press Start
  2. Right clicking on Computer
  3. Selecting Properties
  4. Selecting Advanced system settings
  5. Selecting Environment Variables

Now add each of the above as System Variables

]]>
http://www.robertsindall.co.uk/blog/how-to-set-up-amazon-auto-scaling-group-command-line-tools-on-windows/feed/ 0
How to Setup Pingdom Real User Monitoring in WordPress http://www.robertsindall.co.uk/blog/how-to-setup-pingdom-real-user-monitoring-in-wordpress/ http://www.robertsindall.co.uk/blog/how-to-setup-pingdom-real-user-monitoring-in-wordpress/#comments Sun, 21 Apr 2013 20:54:29 +0000 Robert http://www.robertsindall.co.uk/blog/?p=1300 Pingdom Real User Monitoring to WordPress.]]> In this post shows you how to add Pingdom Real User Monitoring to WordPress.

What is Pingdom?

Pingdom is a uptime and performance monitoring service that has monitoring probe servers all over the world.

What is Real User Monitoring

Real User Monitoring gives you insight into performance and helps you answer questions like, how does your website really perform from a specific country or web browser.

Adding Real User Monitoring in WordPress

Adding a new site to the Real User Monitoring in Pingdom

Then you are given a script to add into the head section of your website


var _prum = [['id', 'XXXXXXXXXXXXXXXXXX'],
             ['mark', 'firstbyte', (new Date()).getTime()]];
(function() {
    var s = document.getElementsByTagName('script')[0]
      , p = document.createElement('script');
    p.async = 'async';
    p.src = '//rum-static.pingdom.net/prum.min.js';
    s.parentNode.insertBefore(p, s);
})();

The javascript above must be placed between two script tags


Then add the script into this file in the head section

/public_html/blog/wp-content/themes/your_theme/header.php

Beware caching

If you are running any WordPress caching plugins remember to clear the cache

Further Reading

]]>
http://www.robertsindall.co.uk/blog/how-to-setup-pingdom-real-user-monitoring-in-wordpress/feed/ 0
Tips and Tricks on how to improve MVC Application Performance http://www.robertsindall.co.uk/blog/how-to-improve-mvc-application-performance/ http://www.robertsindall.co.uk/blog/how-to-improve-mvc-application-performance/#comments Sun, 21 Apr 2013 08:01:59 +0000 Robert http://www.robertsindall.co.uk/blog/?p=1224 In this post we will cover a few tips and tricks to improve ASP.NET MVC Application Performance.

Run in Release mode

Make sure your production application always runs in release mode in the web.config


or change this in the machine.config on the production servers


    
          
    

Only use the View Engines that you require

protected void Application_Start() 
{ 
	ViewEngines.Engines.Clear(); 
	ViewEngines.Engines.Add(new RazorViewEngine()); 
}

Use the CachedDataAnnotationsModelMetadataProvider

ModelMetadataProviders.Current = new CachedDataAnnotationsModelMetadataProvider();

Avoid passing null models to views

Because a NullReferenceException will be thrown when the expression gets evaluated, which .NET then has to handle gracefully.

// BAD
public ActionResult Profile() 
{ 
	return View(); 
}
// GOOD
public ActionResult Profile() 
{ 
	return View(new Profile()); 
}

Use OutputCacheAttribute when appropriate

For content that does not change often, use the OutputCacheAttribute to save unnecessary and action executions.

[OutputCache(VaryByParam = "none", Duration = 3600)]
public ActionResult Categories() 
{ 
	return View(new Categories()); 
}

Use HTTP Compression

 


Remove unused HTTP Modules

If you run into any problems after removing them, try adding them back in.


      
      
      
      

Flush your HTML as soon as it is generated


Turn off Tracing


     
          
     

Remove HTTP Headers

This is more of a security thing


    


 
  
 

Uninstall the URL Rewrite module if not required

This saves CPU cycles used to check the server variable for each request.

Go to "Add or Remove Programs" and find "Microsoft URL Rewrite Module" and select uninstall. 

Don’t write rubbish code

Just don’t.

]]>
http://www.robertsindall.co.uk/blog/how-to-improve-mvc-application-performance/feed/ 3
How to clean up Amazon EBS Volumes and Snapshots http://www.robertsindall.co.uk/blog/how-to-clean-up-amazon-ebs-volumes-and-snapshots/ http://www.robertsindall.co.uk/blog/how-to-clean-up-amazon-ebs-volumes-and-snapshots/#comments Sat, 20 Apr 2013 17:21:41 +0000 Robert http://www.robertsindall.co.uk/blog/?p=1154 In this post we we I will show you how to clean up unused Amazon EBS Volumes and Snapshots.

This is worth doing becuase quite a collection can build up over time and Amazon Web Services has limits on the number you can store; these limits can be increased, but you have to make a Request to Increase the Amazon EBS Volume Limit

What are EBS Volumes?

Volumes behave like raw, unformatted block devices, with user supplied device names and a block device interface. You can create a file system on top of Amazon EBS volumes, or use them in any other way you would use a block device (like a hard drive).

What are Snapshots?

Snapshots are a point-in-time of a volume, which are persisted to Amazon S3. These snapshots can be used as the starting point for new Amazon EBS volumes, and protect data for long-term durability. The same snapshot can be used to instantiate as many volumes as you wish. These snapshots can be copied across AWS regions, making it easier to leverage multiple AWS regions for geographical expansion, data center migration and disaster recovery.

Getting started

Create an Amazon Linux instance and upload your EC2 private key and EC2 certificate and then set them

export EC2_PRIVATE_KEY=pk-QWERTYUIOP.pem
export EC2_CERT=cert-QWERTYUIOP.pem

EBS Volumes available to remove

Use this command to list of all the volumes available to remove

ec2-describe-volumes --region eu-west-1 | grep available | awk '{print $2}' | tr '\n' ' '

All Snapshots

Use this command to list of all snapshots

ec2-describe-snapshots --region eu-west-1 | grep SNAPSHOT | awk '{print $2}' | sort | uniq

All Snapshots in use

Use this command to list all snapshots in use

ec2-describe-images --region eu-west-1 | grep BLOCKDEVICEMAPPING | awk '{print $3}' | sort | uniq

All Snapshots not in use by any AMI’s

Use this command to list all snapshots not associated with an AMI

// all snapshots not associated with an AMI
comm -23 <(echo $(ec2-describe-snapshots --region eu-west-1 | grep SNAPSHOT | awk '{print $2}' | sort | uniq) | tr ' ' '\n') <(echo $(ec2-describe-images --region eu-west-1 | grep BLOCKDEVICEMAPPING | awk '{print $3}' | sort | uniq) | tr ' ' '\n') | tr '\n' ' '

Warning

KNOW WHAT YOUR DOING BEFORE RUNNING THE FOLLOWING COMMANDS

How to delete all EBS Volumes which are unattached

Use this command to delete all volumes which are unattached

// delete all volumes which are unattached
ec2-delete-volume --region eu-west-1 $(ec2-describe-volumes --region eu-west-1 | grep available | awk '{print $2}' | tr '\n' ' ')

How to delete all Snapshots which are not in use

Use this command to delete all snapshots not in use

// run as a single command
for s in $(comm -23 <(echo $(ec2-describe-snapshots --region eu-west-1 | grep SNAPSHOT | awk '{print $2}' | sort | uniq) | tr ' ' '\n') <(echo $(ec2-describe-images --region eu-west-1 | grep BLOCKDEVICEMAPPING | awk '{print $3}' | sort | uniq) | tr ' ' '\n') | tr '\n' ' ')
do
	echo Deleting snapshot $s
	ec2-delete-snapshot --region eu-west-1 $s  
done

I take no responsibility nor blame if something goes wrong.

Good Luck

]]>
http://www.robertsindall.co.uk/blog/how-to-clean-up-amazon-ebs-volumes-and-snapshots/feed/ 3
How to generate a Private Key and Certificate Signing Request CSR http://www.robertsindall.co.uk/blog/how-to-generate-a-private-key-and-certificate-signing-request-csr/ http://www.robertsindall.co.uk/blog/how-to-generate-a-private-key-and-certificate-signing-request-csr/#comments Wed, 03 Apr 2013 20:01:57 +0000 Robert http://www.robertsindall.co.uk/blog/?p=1106 Private Key and Certificate Signing Request CSR and using OpenSSL]]> I keep needing to generate a Private Key and Certificate Signing Request CSR and forgetting the OpenSSL command.

What is OpenSSL for Windows

The OpenSSL Project is a collaborative effort to develop a robust, commercial-grade, full-featured, and Open Source toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) protocols as well as a full-strength general purpose cryptography library.

Download OpenSSL for Windows

You need to download OpenSSL for Windows and then install it.

How to generate a Private Key and a Certificate Signing Request
// generate private key and CSR
openssl req -out www.abc.com.CSR.csr -new -newkey rsa:2048 -nodes -keyout www.abc.com.privateKey.key
How to extract a SSL Certificate from a website
// extract SSL certificate from website
openssl s_client -connect google.com:443
How to convert a Private Key into an RSA Private Key
// convert to RSA Private Key
openssl.exe rsa -in wildcard.example.com.privateKey.key -out wildcard.example.com.privateKey.rsa.key

For more OpenSSL commands

]]>
http://www.robertsindall.co.uk/blog/how-to-generate-a-private-key-and-certificate-signing-request-csr/feed/ 0
Pingdom Maintenance Window using C# http://www.robertsindall.co.uk/blog/pingdom-maintenance-window-using-c/ http://www.robertsindall.co.uk/blog/pingdom-maintenance-window-using-c/#comments Tue, 02 Apr 2013 19:57:51 +0000 Robert http://www.robertsindall.co.uk/blog/?p=1077 Maintenance Window for other tasks to happen without effecting your up time reports, by pausing and unpausing all your Pingdom checks.]]> In this post we will create a simple console app to pause and unpause all the Pingdom checks, this can then be used to create a maintenance window for other tasks to happen without effecting your up time reports.

What is Pingdom?

Pingdom is a uptime and performance monitoring service that has monitoring probe servers all over the world.

How to create a Maintenance Window?

Using the Pingdom REST API we can modify all the checks in one call

namespace PingdomMaintenanceWindowApp
{
    using System;
    using System.Configuration;
    using System.Text;

    using RestSharp;

    public class PingdomMaintenanceWindow
    {
        private string AppKey
        {
            get
            {
                return ConfigurationManager.AppSettings["app-key"];
            }
        }

        private string Username
        {
            get
            {
                return ConfigurationManager.AppSettings["authorization.username"];
            }
        }

        private string Password
        {
            get
            {
                return ConfigurationManager.AppSettings["authorization.password"];
            }
        }

        public string Message
        {
            get
            {
                return message;
            }
        }

        private const string Host = "https://api.pingdom.com:443";

        private const string Resource = "/api/2.0/checks";

        private readonly RestClient client;

        private readonly RestRequest request;

        private string message;

        public PingdomMaintenanceWindow()
        {
            client = new RestClient(Host);
            client.AddDefaultHeader("Accept","*/*");
            client.AddDefaultHeader("App-Key", AppKey);
            client.Authenticator = new HttpBasicAuthenticator(Username, Password);

            request = new RestRequest(Resource, Method.PUT);
        }

        public void Start()
        {
            PauseChecks(true);
        }

        public void Stop()
        {
            PauseChecks(false);
        }

        private void PauseChecks(bool is_paused)
        {
            request.AddParameter("paused", is_paused ? "true" : "false");

            var response = client.Execute(request);

            if (response.ResponseStatus == ResponseStatus.Completed)
            {
                message = response.Content;
            }
            else
            {
                message = response.ErrorMessage;

                if (response.ErrorException != null)
                {
                    throw response.ErrorException;
                }
            }
        }
    }
}

The console app provides a little bit of simple UX

using System;

namespace PingdomMaintenanceWindowApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var command = "";

            if (args.Length == 0)
            {
                Console.WriteLine("");
                Console.WriteLine("Pingdom Maintenance Window options:");
                Console.WriteLine("");
                Console.WriteLine("start");
                Console.WriteLine("stop");
                Console.WriteLine("");
                Console.WriteLine("e.g. PingdomMaintenanceWindowApp.exe start");
                Console.WriteLine("");
                Console.WriteLine("Or type command now and press enter to proceed...");
                command = Console.ReadLine();
            } 
            else
            {
                command = args[0];
            }

            var maintenanceWindow = new PingdomMaintenanceWindow();

            if(command == "start")
            {
                Console.WriteLine("Starting maintenance window...");
                maintenanceWindow.Start();
            } 
            else if (command == "stop")
            {
                Console.WriteLine("Stopping maintenance window...");
                maintenanceWindow.Stop();
            }
            else
            {
                Console.WriteLine("Unknown command: {0}", command);
                return;
            }

            Console.WriteLine("");
            Console.WriteLine(maintenanceWindow.Message);
            
        }
    }
}

Or to use the menu system just run the app.

You can download the code from GitHub

]]>
http://www.robertsindall.co.uk/blog/pingdom-maintenance-window-using-c/feed/ 0