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
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:
Your feedback encourages the volunteers in this community to continue contributing
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:
Your feedback encourages the volunteers in this community to continue contributing
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......
I like this, its an elegant solution. Let me try this