Status Cake API

Posted on Sunday, February 8, 2015


Now that I have Status Cake set up and working (see Setting up Status Cake), see I want to see what if anything I can do with their API.

It would be nice to ping their API and get an up/down message or, even better, a message showing which IP hit, when, and if they succeeded or failed.




 

Poking around


First, their documentation for their API is at https://www.statuscake.com/api/ [1]






 

API Key


First you need to get your API key before you go any further.




After logging in, Click User Details








Click on API Key











Grab your API key.  Mine is

IcGi8dD73X5iS1FdQHlA 

(I am going to reset after I finish writing this document)









I also noticed this.  Looks like I can call the API 250 times a day?  Ahh found it https://www.statuscake.com/api-limits/ [2].  Free account is limited to 250/day, paid account has no limit.



Ok now that I have my API key what is the next thing to do?

Try this curl (put in your APIKey and Username.


  > curl -H "API: [APIKey]" -H "Username: [UserName]" -X GET https://www.statuscake.com/API/ContactGroups/




When I run this.  (Curl then pipe to jq to pretty-print it.


  > curl -H "API: IcGi8dD73X5iS1FdQHlA" -H "Username: patman" -X GET https://www.statuscake.com/API/ContactGroups/ | jq '.'


I get back



My list of Groups, and the emails associated with them.







All Tests


Get a list of all your current tests.



  > curl -H "API: [APIKey]" -H "Username: [UserName]" -X GET https://www.statuscake.com/API/Tests/


When I run


  > curl -H "API: IcGi8dD73X5iS1FdQHlA" -H "Username: patman" -X GET https://www.statuscake.com/API/Tests/ | jq '.'


I get back all my test




My Status is Up.








Specific Test



My Test ID is 329630.  I can do a restful call on just that test.




  > curl -H "API: [APIKey]" -H "Username: [UserName]" -X GET https://www.statuscake.com/API/Tests/Details/?TestID=[TestID]


When I run


  > curl -H "API: IcGi8dD73X5iS1FdQHlA" -H "Username: patman" -X GET https://www.statuscake.com/API/Tests/Details/?TestID=329630 | jq '.'


I get back all the details of my specific test.








This needs a little more investigation to read properly.  Looking at their documentation at https://www.statuscake.com/api/Tests/Get%20Detailed%20Test%20Data.md [3]



"Status": "Up", // String of current status
"Uptime": 0, // Uptime in Percentage form.
"CheckRate": 60, // Check rate in seconds.
"Timeout": 40, // The timeout value set in seconds
"LogoImage": "", // If a logo image has been set for public reporting
"WebsiteHost": "Various", // User entered value for Website Host
"NodeLocations": [
"UK","JP","SG1","SLC"
], // Array of locations selected to test from. See get locations
"FindString": "", // String to look for
"DoNotFind": false, // // If a string should be found or not fine
"LastTested": "2013-01-20 14:38:18", // Last time testing started
"NextLocation": "USNY", // The next location testing will start from
"Processing": false, // If currently being tested
"ProcessingState": "Pretest", // The current test status
"ProcessingOn": "dalas.localdomain", // What server is processing
"DownTimes": "0", // The amount of consecutive downtimes recorded



Looks like they need to update their docs.   Its missing Confirmation and a few others, but the basic idea is there.

What I really want to know is can I query it and determine, if it's down, how long its been down and how many checks have run that say its down.  That would be ideal.



I think I have it.

I need the following.

LastTested
Status
Downtimes


Let me take my server down and watch it.





1 Downtimes, and looking at my lots it was checked from 4 locations















4 Downtimes








5 Downtimes then I was sent a message.  








Looking at a few things I found https://www.statuscake.com/API/Locations/json






Here are my logs before an email trigger was sent.





107.155.125.29 - - [30/Jan/2015:13:49:37 -0700] 
107.155.90.144 - - [30/Jan/2015:13:49:45 -0700] 
37.157.246.146 - - [30/Jan/2015:13:49:53 -0700] 
37.235.55.205 - - [30/Jan/2015:13:49:57 -0700] 
107.155.90.144 - - [30/Jan/2015:13:50:36 -0700]
50.2.139.16 - - [30/Jan/2015:13:51:28 -0700] 
107.155.90.144 - - [30/Jan/2015:13:51:53 -0700] 
107.155.90.144 - - [30/Jan/2015:13:51:55 -0700] 
37.235.55.205 - - [30/Jan/2015:13:56:02 -0700] 


Downtime was
detected at
13:49:37 
Alert was sent out after alert
            13:56:02
# of checks down checks
            9
# of unique IP addresses
            6

Total time once server was seen as down, before email went out
            6:25

Throw on the +5 minutes before to account for the maximum time, in case it went down just after the last check.   

            11:25

That is with the free 5 min fidelity.  If it was paid it goes down to 1 min.


Further testing.

When I got up to 10 downtimes





Here is my log.


107.155.125.29 - - [30/Jan/2015:13:49:37 -0700] 
107.155.90.144 - - [30/Jan/2015:13:49:45 -0700] 
37.157.246.146 - - [30/Jan/2015:13:49:53 -0700] 
37.235.55.205 - - [30/Jan/2015:13:49:57 -0700] 
107.155.90.144 - - [30/Jan/2015:13:50:36 -0700] 
50.2.139.16 - - [30/Jan/2015:13:51:28 -0700] 
107.155.90.144 - - [30/Jan/2015:13:51:53 -0700] 
107.155.90.144 - - [30/Jan/2015:13:51:55 -0700]
37.235.55.205 - - [30/Jan/2015:13:56:02 -0700] 
108.61.196.32 - - [30/Jan/2015:14:01:09 -0700] 
185.38.32.15 - - [30/Jan/2015:14:06:20 -0700] 
46.246.28.90 - - [30/Jan/2015:14:12:05 -0700] 
178.32.72.135 - - [30/Jan/2015:14:16:34 -0700] 
162.245.216.227 - - [30/Jan/2015:14:21:30 -0700] 




I have 14 hits in my log.  Looks like I have 7 different time frames it tries to hit the server.  Looks like when its first down it tries to confirm its down by hitting it from several locations.

The first time group has 5 unique IP addresses it was hit from. 
It was then hit 6 other times (roughly 5 minutes apart).  If I don't count the first hit as a downtime?  That reduces the unique IPs in the first group down to 4 unique hits.

4+6 = 10

I am guessing that is the case?  The first negative is not counted in the total, nor are hits from the same IP address.

Let's experiment a little!

I left my site down for a bit longer.   Every 5 minutes my Downtimes incremented by +1.  I ran this test from 10 all the way to 20 and it incremented +1 each 5 minutes.




Let me bring the site back up.  Let StatusCake Confirm its up.  Then bring it back down again.  I want to confirm my theory on the DownTimes count.


5.135.29.124 - - [30/Jan/2015:15:34:07 -0700] 
37.122.208.79 - - [30/Jan/2015:15:34:15 -0700] 
5.135.29.124 - - [30/Jan/2015:15:34:24 -0700] 
37.235.55.205 - - [30/Jan/2015:15:34:33 -0700] 
37.157.246.146 - - [30/Jan/2015:15:35:10 -0700]



After this DownTimes = 1


5.135.29.124 - - [30/Jan/2015:15:34:07 -0700] 
37.122.208.79 - - [30/Jan/2015:15:34:15 -0700] 
5.135.29.124 - - [30/Jan/2015:15:34:24 -0700] 
37.235.55.205 - - [30/Jan/2015:15:34:33 -0700] 
37.157.246.146 - - [30/Jan/2015:15:35:10 -0700]



Yellow is original hit, which is hit twice.  Then 3 unique confirmations!  Perfect!




5.135.29.124 - - [30/Jan/2015:15:34:07 -0700] 
37.122.208.79 - - [30/Jan/2015:15:34:15 -0700] 
5.135.29.124 - - [30/Jan/2015:15:34:24 -0700] 
37.235.55.205 - - [30/Jan/2015:15:34:33 -0700] 
37.157.246.146 - - [30/Jan/2015:15:35:10 -0700] 
107.155.90.144 - - [30/Jan/2015:15:35:45 -0700] 
107.155.90.144 - - [30/Jan/2015:15:35:50 -0700]
37.122.208.79 - - [30/Jan/2015:15:36:23 -0700] 
37.235.53.240 - - [30/Jan/2015:15:36:59 -0700] 




After this  DowntTimes = 5

The first quick group counts as 1.  The first IP then 3 additional IP addresses.  Each IP after that counts as +1





5.135.29.124 - - [30/Jan/2015:15:34:07 -0700] 
37.122.208.79 - - [30/Jan/2015:15:34:15 -0700]
5.135.29.124 - - [30/Jan/2015:15:34:24 -0700] 
37.235.55.205 - - [30/Jan/2015:15:34:33 -0700] 
37.157.246.146 - - [30/Jan/2015:15:35:10 -0700]
(Counts as 1)

107.155.90.144 - - [30/Jan/2015:15:35:45 -0700] 
107.155.90.144 - - [30/Jan/2015:15:35:50 -0700] 
37.122.208.79 - - [30/Jan/2015:15:36:23 -0700] 
37.235.53.240 - - [30/Jan/2015:15:36:59 -0700]
(counts as +4, total of 5)

192.241.221.11 - - [30/Jan/2015:15:37:40 -0700] 
37.235.55.205 - - [30/Jan/2015:15:38:17 -0700] 
176.56.230.59 - - [30/Jan/2015:15:38:49 -0700]
(counts as +3, total of 8)



This gives me 8 downtimes


DownTimes  < Actual failed hits by at least 3.


And DownTimes comes from at least  [1 + (# of Confirmation servers)] unique IP addresses.

Also I believe with the paid account you can set which IP addresses you want hitting your site, for example only US IP addresses, or only US an Africa.  (If someone can elaborate on this that would be great)













References

[1]        Status Cake API
                        https://www.statuscake.com/api/
                Accessed 1/2015
[2]        StatusCake API Limits For Free Users
                        https://www.statuscake.com/api-limits/
                Accessed 1/2015
[3]        GET /API/Tests/Details/?TestID=[TestID]
                Accessed 1/2015



No comments:

Post a Comment