Gateway status query

Hi

I would like to query my gateway status and send a notification when its offline.

I have googled and tried many iterations of the code below but I suspect I’m missing something. I cant figure out how to include the gateway API and I’m sure I have the TTI url wrong.

Has anyone managed to do this and could you please help me with my code.

const { Analysis } = require("@tago-io/sdk");
const axios = require("axios");



function getData() {
      const response = axios ({
      url: "https://eu1.cloud.thethings.network/api/v3/gs/gateways/eui-mygateway/connection/stats",
      method: "GET"
    })

    console.log(response.status)
    }


// The function myAnalysis will run when you execute your analysis
function myAnalysis(context, scope) {
  getData();
}

module.exports = new Analysis(myAnalysis);





Thanks
Flaxie

@vitor
@guilhermeco
@alinetusi

hi @flaxies,

Your analysis function needs to be like this:

const { Analysis } = require("@tago-io/sdk");
const axios = require("axios");

async function getData(context) {
      const response = await axios ({
      url: "https://eu1.cloud.thethings.network/api/v3/gs/gateways/eui-mygateway/connection/stats",
      method: "GET"
    })

    context.log(response.status);
    context.log(response.data);
 }

function myAnalysis(context, scope) {
  getData(context);
}

module.exports = new Analysis(myAnalysis);

Use context.log to print logs in your analysis console. Your function getData I put response.data you to see what the TTI is responding to, probably you will get some error of authentication, check the TTI documentation to solve this in your request

1 Like

Hi Flaxie, I’m trying to do exactly the same thing. We need to monitor our gateways. Do have something working, and if so, would you be willing to share your solution?

I’m not getting a response from the similar call, so most likely an authentication issue. So a coding example from a working example would be very helpful for me.

Thanks,
Vincent

1 Like

Ok, I just found the answer on my own question. I missed indeed the authorization part in the call:

.
 method: "GET",
 headers: {
  Authorization: "Bearer [Your Gateway Api Key]",
  }

Vincent

1 Like

Hi @vincent.raaijmakers

I used the script suggested by eger but just used the following url https://mapper.packetbroker.net/api/v2/gateways/netID=000013,tenantID=ttn,id= ***********
and added the gateway id. Worked well for me.

Cheers Flaxie

Thanks for the follow up! I finished my script yesterday, not sure if it is the best solution but it seems to work reliably. Our gateways are on V3 here in North America. URL is slightly different.

Vincent

1 Like