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!

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

Splunk Decoded: Business Transactions vs Business IQ

It’s the morning of Black Friday, and your e-commerce site is handling 10x normal traffic. Orders are flowing, ...

Fastest way to demo Observability

I’ve been having a lot of fun learning about Kubernetes and Observability. I set myself an interesting ...