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
1 Solution

livehybrid
SplunkTrust
SplunkTrust

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();

🌟 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

View solution in original post

livehybrid
SplunkTrust
SplunkTrust

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();

🌟 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

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!

Data Management Digest – December 2025

Welcome to the December edition of Data Management Digest! As we continue our journey of data innovation, the ...

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...