Coder Social home page Coder Social logo

ispoweron's Introduction

isPowerOn

Serverless API to track if anything you want is responsive or not with StatusPage.io

What is this?

During the 2021 Texas Power Crisis, I wanted a simple way to be able to tell if my home's power had returned or not while staying at my parents house. Originally, I had a Raspberry Pi setup with a cronjob that spammed my phone with the Telegram API using curl.

This is an improvement on that concept.

How does this work?

Server-side logic

Using Firebase Functions and Firestore, each device/location/app/whatever will correspond to a Component on StatusPage.io.

This requires your device/service/whatever to regularly send out "checkIn" requests to this serverless API. If a component has not "checked in" in within a predefined interval, it will be updated on StatusPage.io and an Incident will be created. The next time that component "checks in", the Incident will be resolved and the component updated.

Client-side logic

There barely is any! (That's the point!)

  • Run crontab -e
*/10 * * * * curl "https://YOUR_DATACENTER-YOUR_PROJECT_ID.cloudfunctions.net/concierge-checkIn?id=SomeRandomDocumentId"

Setup

  • Make a StatusPage.io account

  • Create a Component that corresponds to the device/service/whatever you want to monitor (the group doesn't matter).

  • Install dependencies (Node.js version 14 and NPM version 7 required):

    cd functions/
    npm install
    
  • Deploy this project to firebase using the Firebase CLI.

  • Acquire a StatusPage.io API key

  • Save that API key to the firebase functions config:

    firebase functions:config:set statuspage.key="12345-6789-abcd-efgh-99999999"
    
  • Redeploy for changes to take effect:

    firebase deploy
    
  • Locate the full URL for the /concierge-makeReservations endpoint for your Firebase function. It should be the one with the *.cloudfunctions.net domain.

  • Once located, find the page_id of your StatusPage.io page. This can be found by going to https://manage.statuspage.io/ and paying attention to the url slug in this pattern:

    https://manage.statuspage.io/pages/PAGE_ID_GOES_HERE/incidents
    
  • Now that you have the full URL of your makeReservations function and the page_id, combine them into a URL and open it in your browser.

    https://YOUR_DATACENTER-YOUR_PROJECT_ID.cloudfunctions.net/concierge-makeReservations?pageId=PAGE_ID_GOES_HERE
    
  • Once you've opened that in your browser and the page completely loads, your StatusPage.io Components should have imported into the Firebase Firestore console. You will need to open the makeReservations URL again every time you add a new Component that you want to monitor.

  • Now that your components are added to the Firestore database, you should see a collection named components:

    components

  • Copy or make note of the document name in the database (the part that's pixelated)

  • With the document name noted, you can now produce the "checkIn" URL that can be curl'd in a crontab.

    https://YOUR_DATACENTER-YOUR_PROJECT_ID.cloudfunctions.net/concierge-checkIn?id=DOCUMENT_NAME_GOES_HERE
    
  • Make sure that whatever service you want calls this regularly to be marked as "online".

ispoweron's People

Contributors

au5ton avatar

Watchers

James Cloos avatar  avatar

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.