copied from here
rules.JSRule({
name: "pihole API rule",
description: "Access to pihole API",
triggers: [triggers.GenericCronTrigger("0/40 * * * * ? *")],
execute: (event) => {
var response = actions.HTTP.sendHttpGetRequest("http://localhost:8080/rest/items?metadata=statedescription&recursive=false");
const items = JSON.parse(response);
let itemCount = 0;
items.forEach(item => {
if (item.type.startsWith('Number:')) {
if (item.stateDescription == undefined) {
console.log(item.type + ' ' + item.name + ' has no state description at all');
itemCount++;
} else if (item.stateDescription.pattern.includes('%unit%')) {
console.log(item.type + ' ' + item.name + ' has state description with unit placeholder');
itemCount++;
} else if (item.metadata == undefined || item.metadata.stateDescription == undefined) {
console.log(item.type + ' ' + item.name + ' has a state description not set in metadata');
itemCount++;
}
}
console.log('Total number of items that need your attention: ' + itemCount);
});