Code Monkey home page Code Monkey logo

statuscakedsc's Introduction

StatusCakeDSC

A PowerShell Desired State Configuration (DSC) Provider for simple status checks on Statuscake.com. Gives PowerShell users a nice, declarative syntax for defining checks as part of their infrastructure-as-code repositories.

badge

Requirements

  • PowerShell/WMF 5.0+
  • StatusCake account & API Key
  • A check target

Quick Install

iex ([WebClient].DownloadString("https://githubusercontent.com/stopthatastronaut/StatusCakeDSC/master/install.ps1"))

Installing via git clone

  • Clone the repo down to your local machine
  • Use junction.exe (from the sysinternals resource kit) to junction c:\Program Files\WindowsPowershell\Modules\StatuscakeDSC to the corresponding repo location
  • Test this has worked correctly by restarting your powershell session and running

Get-DSCResource -modulename StatusCakeDSC

Installing via PSGallery

The excellent CVandal has added PSGallery publishing to the resource, so you should be able to insall the resource using Install-Module StatusCakeDSC

How to use

The quick start:

configuration MyStatusCakeConfig
{
    Import-DscResource -Name StatusCakeDSC
    
    node(hostname)
    {
        StatusCakeContactGroup DevOpsGroup
        {
            Ensure = "present"
            GroupName = "DevOpsEngineers"
            Email = @(	"[email protected]", 
            			"[email protected]", 
                        "[email protected]")
            Mobile = "+1-111-1111"
            PingUrl = "https://infra.organisation.com/statusping"
        }

        StatusCakeTest WebsiteToCheck
        {
            Ensure = "present"
            Name = "My Website Check"
            Url = "http://www.organisation.com/ping/"
            ContactGroup = "DevOpsEngineers"
        }
    }
}

MyStatusCakeConfig -OutputPath $env:tmp\StatusCake
Start-DSConfiguration $env:tmp\StatusCake -verbose -wait -force

Running Get-DscResource -Module StatusCakeDSC -Syntax Will give you all your possible parameters.

There will be further documentation available by running Get-Help about_DSCResource_StatusCakeDSC as soon as I have time to write it

Credentials

NOTE: As of version 2.0, credentials are protected in PSCredential Objects

v1.x

You can either Specify UserName and ApiKey directly in your DSC configuration, or you can use a locally-stored file (useful for testing).

To pass your credentials in the normal way:

StatusCakeContactGroup DevOpsGroup
{
    Ensure = "present"
    GroupName = "DevOpsEngineers"
    Email = @("[email protected]", "[email protected]", "[email protected]")
    Mobile = "+1-111-1111"
    PingUrl = "https://infra.organisation.com/statusping"
    ApiKey = "ASDFGHJKLOIUYTREW"
    UserName = "ExampleUserName"
}

To use the .creds option, you'll need a .creds file in the module's root directory, with the following content:

{
    "ApiKey":  "ASDFGHJKLOIUYTREW",
    "UserName":  "ExampleUserName"
}

Using the .creds option does not support multiple StatusCake accounts, and is best reserved for testing purposes. We recommend you don't commit credentials to public source control, naturally.

v2+

You can either Specify UserName and ApiKey directly in your DSC configuration, with the following params

$secureapikey = ConvertTo-SecureString "ASDFGHJKLOIUYTREW" -asplaintext -force # not recommended. See note below.
$apicreds = [PSCredential]::new("ExampleUserName", $secureapikey)


StatusCakeContactGroup DevOpsGroup
{
    Ensure = "present"
    GroupName = "DevOpsEngineers"
    Email = @("[email protected]", "[email protected]", "[email protected]")
    Mobile = "+1-111-1111"
    PingUrl = "https://infra.organisation.com/statusping"
    ApiCredential = $apicreds
}

or you can create a .securecreds file in the same location as the Module, with the following format. The secure string will be decrypted with the local machine's default key (using ConvertTo-SecureString). Strings serialized with another key will fail here, so take care.

{
    "ApiKey":  "serializedsecurestringrepresentationofyourapikey",
    "UserName":  "ExampleUserName"
}

You can use createcredsfile.ps1 to create securecreds files. This script will prompt for your credentials and drop them into %ProgramFiles%\WindowsPowerShell\Modules\StatusCakeDSC.

More information on securing credentials with PSCredential Objects, see the following link

A note on API keys and rate limits

At the time of writing (Dec 2017), Statuscake free accounts have rate limiting applied which makes the resource misbehave, throwing 500 errors. Paid accounts have no such limitation. We'll update this readme if and when that changes.

Backoff and retry for rate-limits is a flagged-off feature at present, since limiting in the API is not granular.

Testing

To run the full suite of automatic tests, you will need valid credentials for an Active Statuscake account, in a .creds o .securecreds file. There is a subset of tests that can run without, but for full functionality, you need them.

They also expect two contact groups to exist, called "stopthatastronaut" and "stopthatastronaut2". Change these to match your environment or add some groups to your environment.

Contribs/Reporting bugs

Feel free to submit PRs or bug reports via Github. I don't bite. Much.

Publishing to the PS Gallery

This Module has Continuous Publishing configured via Octopus Deploy.

Any commit on master will trigger an Octopus Deploy instance using TakoFukku. That instance will run tests and, if successful, run a publishing step.

The publishing step checks the latest version available on PS Gallery, and compares that to the version in StatusCakeDSC.psd1. If the manifest version is higher than the published version, Octopus then attempts to publish the new version to the Gallery, and tries to tag the commit on github. Be aware that incrementing the version will attempt to publish the module immediately.

statuscakedsc's People

Contributors

cvandal avatar lawrencewilson avatar matt-richardson avatar stopthatastronaut avatar

Stargazers

 avatar  avatar

Watchers

 avatar

statuscakedsc's Issues

Help fails in Powershell core Update-Help

As follows:

update-help : Failed to update Help for the module(s) 'StatusCakeDSC' with UI culture(s) {en-AU} : The value of the HelpInfoUri key in the module manifest must resolve to a container or root URL on a website where the help files are stored. The HelpInfoUri 'https://github.com/stopthatastronaut/StatusCakeDSC' does not resolve to a container.                                 At line:1 char:1    

Credentials should be protected

BasicUser and BasicPassword should be encapsulated into a PSCredential

ApiKey could also go into a PSCredential, with the username part ignored

Needs better and more documentation

About_DSCResource_StatuscakeContactGroup.help.txt
About_DSCResource_StatuscakeSSL.help.txt
About_DSCResource_StatuscakeTest.help.txt

All need some content

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.