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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Laser Bananas and Edge Hubs: Exploring Operational Technology (OT) Data Through a ...

  OT is a different environment to traditional IT and can have interesting challenges when interfacing the ...

Event Series: Mastering AI Tokenomics and Splunk Agent Observability

Beyond the Black Box: Correlating AI Performance and Tokenomics with Splunk Agent Observability   As ...

span_metrics: The OpenTelemetry-Idiomatic Way to See Inside Your Services

You open a trace in Splunk Observability Cloud and everything looks fine. One root span, order-pipeline, with ...