Indexed items?


Is it possible to add a variable to an item name to make it easy to repeat similar items? Or do i have to hardcode all items in my item file?

I’m adding monitoring of servers to my OH2 setup and i have some items that i need to repeat 20 times
I use SNMP for the monitoring 20 disk in the Synology NAS and for 1 disk the variable look like this.

String NAS_S1_DiskID_1			"Disk ID [%s]"									<number>		(Server_1_disks)	{ snmp="<[]" }
String NAS_S1_DiskModel_1		"Disk Model [%s]"									<text>			(Server_1_disks)	{ snmp="<[]" }
Number NAS_S1_DiskStatus_1		"Disk Status [MAP(]"		<text>			(Server_1_disks)	{ snmp="<[]" }
Number NAS_S1_DiskTemp_1		"Disk Temperature [%.2f  °C]"						<temperature>	(Server_1_disks)	{ snmp="<[]" }
Number NAS_S1_DiskLoad_5m_1		"Disk use avg. 5min [%.1f %%]" 				<number> 		(Server_1_disks) 	{ snmp="<[ .]" }

But I have 20 disks can this be done with a for loop or something where the _1 is substituted by a variable?

For ($i=1 to 10){
   String NAS_S1_DiskID_$i			"Disk ID [%s]"									<number>		(Server_1_disks)	{ snmp="<[$i:5000]" }

I don’t believe there’s any option for running any kind of script inside an items file that way.

Short answer is no. If the pain is enough you could write a script to generate the. Items file for you.

But I will say that OH probably isn’t the best tool for this and you would probably be happier with a tool like Nagios.

Thx @rlkoshak for sending me in a better direction… now use telegrah with influx db and grafana. only problem is that I know don’t have actual value in OH2 only charts and status…
Pitty there is no simple JDBC binding for getting stuff from a DB.

Sounds like a good first binding for someone to write up as their first contribution to OH (hint hint).

That wouldn’t solve your problem though. You would still have to create each Item.

But it just occurred to me that you could write a script to generate the new Items using the OH REST API. That might be a compromise approach.