Splunk Observability Cloud

Using return values in a dashboard or detector ?

Silah
Path Finder

Hi All

 

I am building synthetic monitoring in Observability Cloud for an online shop.

One thing I want to monitor is whether or not an items stock status is correct.

I have a synthetic step "Save return value from JavaScript" to this effect:

function checkStockStatus() {
  if (document.body.textContent.includes("OUT OF STOCK")) {
    return "oos";
  }
  return "instock";
}

checkStockStatus();

 

I am storing this in a variable named stockStatus

Is there any way I can use the value of this variable in a dashboard, or to trigger an alert ?

For example, say I am selling a golden lamp, and it gets sold out, how can I get a dashboard to show "oos" somewhere ?

 

Thanks 

 

 

 

0 Karma

livehybrid
Ultra Champion

Hi @Silah 

I dont think its possible to save these after the execution - however I wonder if you could use the javascript execution to send a metric to Splunk Obervability like this:

function sendStockMetric() {
  const status = document.body.textContent.includes("OUT OF STOCK") ? 0 : 1;
  
  fetch('https://ingest.{REALM}.signalfx.com/v2/datapoint', {
    method: 'POST',
    headers: {
      'X-SF-TOKEN': 'YOUR_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      gauge: [{
        metric: 'shop.item.stock_status',
        value: status,
        dimensions: {
          item: 'your_product_001',
          status: status === 1 ? 'instock' : 'oos'
        }
      }]
    })
  });
}

sendStockMetric();

:glowing_star: Did this answer help you? If so, please consider:

  • Adding karma to show it was useful
  • Marking it as the solution if it resolved your issue
  • Commenting if you need any clarification

Your feedback encourages the volunteers in this community to continue contributing

0 Karma

Silah
Path Finder

Ok, I give up.. do you have anywhere I can read about how to use ingest API ?

I am able to send the payload to the endpoint in my realm, using a token I created for it. I get a HTTP200 response but the metrics don't get created anywhere..

I have been searching the documentation but splunk docs are in general abysmal I think, I haven't found anything useful at all.....

Any hints? 

Thanks

 

Disregard, ChatGPT figured out my problem for me......

0 Karma

Silah
Path Finder

I like this, its an elegant solution. Let me try this

0 Karma
Get Updates on the Splunk Community!

See just what you’ve been missing | Observability tracks at Splunk University

Looking to sharpen your observability skills so you can better understand how to collect and analyze data from ...

Weezer at .conf25? Say it ain’t so!

Hello Splunkers, The countdown to .conf25 is on-and we've just turned up the volume! We're thrilled to ...

How SC4S Makes Suricata Logs Ingestion Simple

Network security monitoring has become increasingly critical for organizations of all sizes. Splunk has ...