This script is based on zabbix 2.0 api and LLD which is only available in zabbix 2.0
Description
The intended usage of this script is to automatically generate graphs containing all of the items generated by a LLD rule, for all hosts linked to a specified template.
Currently LLD prototypes allow you to define graphs containing prototype items. These graph prototypes can only contain prototype items, there is no option to create a graph containing all discovered items.
For example, for a discovery rule named volume discovery I have the following item prototypes:
And I have the following graph prototypes:
In a real world scenario I end up with one graph per discovered volume, with no option to create a graph containing all discovered volumes.

What I needed was a graph containing all items generated by the same discovery rule. This script allows you to create the following types of graphs:



Usage
Download the archive, extract and give the zabbix user rx permissions on the lld_all_graph.pl script, edit it, specifically the parameters below, run it, test it, cron it.
The script connects using $user and $password via json api and enumerates all hosts that are linked to $template. For each host it enumerates the items that match $regexes[0] or $regexes[1]. It adds them all up and creates (for each host enumerated) a graph named $graph. If the graph already existed, then it first deletes it.
Multiple graph options can be set including the graph type (normal, stacked), whether the min/max values are fixed or calculated, the min/max fixed values, if the triggers are shown. Also, multiple item options can be set including the item drawing type (line, filled, bold line, etc.), the y axis side (left, right) and the function used (avg, min, max, etc.). Colors are chosen automatically.
Gotchas
You only need to specify $regexes[0] (delete de line of $regexes[1]) for simple graphs such as WIN Processor "ALL" above. This adds all items matching $regexes[0] to the graph, using dark colors. If there are more than 21 items in the graph, light colors are also used. A number of 42 items per graph is supported.
Specifying both $regexes[0] and $regexes[1] will generate graphs such as WIN Volumes "ALL" above, where items matching $regexes[0] are alternated with items matching $regexes[1], using alternated dark and light colors.
In my example $regexes[0] matches items for free space and use dark colors, and $regexes[1] matches items for used space and use light colors, as in the graph above. A number of 21 items per regex is supported, 42 in total.
The script does not verify the json return value for errors. For example, it will say "graph created" even if zabbix rejected the json api call.
Update 1
The script now automatically exludes prototype items, you no longer have to exclude them by using regex.
Added new colors, 42 now available.
Added global variable for drawtype and calcfunction. Showtriggers now defaults to true.
Description
The intended usage of this script is to automatically generate graphs containing all of the items generated by a LLD rule, for all hosts linked to a specified template.
Currently LLD prototypes allow you to define graphs containing prototype items. These graph prototypes can only contain prototype items, there is no option to create a graph containing all discovered items.
For example, for a discovery rule named volume discovery I have the following item prototypes:
Code:
WIN Volume "{#VOLNAME} ({#VOLLABEL})" bytes/sec read
WIN Volume "{#VOLNAME} ({#VOLLABEL})" bytes/sec total
WIN Volume "{#VOLNAME} ({#VOLLABEL})" bytes/sec write
WIN Volume "{#VOLNAME} ({#VOLLABEL})" bytes free
WIN Volume "{#VOLNAME} ({#VOLLABEL})" bytes used
Code:
WIN Volume "{#VOLNAME} ({#VOLLABEL})" bytes/sec stack
WIN Volume "{#VOLNAME} ({#VOLLABEL})" bytes free stack
Code:
Volume discovery: WIN Volume "C: (Windows)" bytes/sec stack Volume discovery: WIN Volume "C: (Windows)" bytes stack Volume discovery: WIN Volume "D: (Data)" bytes/sec stack Volume discovery: WIN Volume "D: (Data)" bytes stack Volume discovery: WIN Volume "F: (Backup)" bytes/sec stack Volume discovery: WIN Volume "F: (Backup)" bytes stack Volume discovery: WIN Volume "G: (Storage)" bytes/sec stack Volume discovery: WIN Volume "G: (Storage)" bytes stack

What I needed was a graph containing all items generated by the same discovery rule. This script allows you to create the following types of graphs:



Usage
Download the archive, extract and give the zabbix user rx permissions on the lld_all_graph.pl script, edit it, specifically the parameters below, run it, test it, cron it.
Code:
$user = "Admin"; ### username $password = "zabbix"; ### password $template = "Windows WIN"; ### only add graphs to hosts linked to this template $url = "http://127.0.0.1/api_jsonrpc.php"; ### intenal zabbix url $graph = 'WIN Volume "ALL" bytes stack'; ### create a graph with this name in each host $graphtype = 1; ### 0=normal, 1=stacked $mintype = 1; ### 0=calculated, 1=fixed $maxtype = 0; ### 0=calculated, 1=fixed $minvalue = 0; $maxvalue = 100; $showtriggers = 1; $drawtype = 0; ### 0=line, 1=filled, 2=boldline, 3=dot, 4=dashed, 5=gradient $calcfunction = 2; ### 1=min, 4=max, 2=avg, 7=all ### add graph items mathing these regexes, maximum 2 $regexes[0] = '^WIN\sVolume\s".*"\sbytes\sfree'; $regexes[1] = '^WIN\sVolume\s".*"\sbytes\sused'; ### delete this line if not needed.
Multiple graph options can be set including the graph type (normal, stacked), whether the min/max values are fixed or calculated, the min/max fixed values, if the triggers are shown. Also, multiple item options can be set including the item drawing type (line, filled, bold line, etc.), the y axis side (left, right) and the function used (avg, min, max, etc.). Colors are chosen automatically.
Gotchas
You only need to specify $regexes[0] (delete de line of $regexes[1]) for simple graphs such as WIN Processor "ALL" above. This adds all items matching $regexes[0] to the graph, using dark colors. If there are more than 21 items in the graph, light colors are also used. A number of 42 items per graph is supported.
Specifying both $regexes[0] and $regexes[1] will generate graphs such as WIN Volumes "ALL" above, where items matching $regexes[0] are alternated with items matching $regexes[1], using alternated dark and light colors.
In my example $regexes[0] matches items for free space and use dark colors, and $regexes[1] matches items for used space and use light colors, as in the graph above. A number of 21 items per regex is supported, 42 in total.
The script does not verify the json return value for errors. For example, it will say "graph created" even if zabbix rejected the json api call.
Update 1
The script now automatically exludes prototype items, you no longer have to exclude them by using regex.
Added new colors, 42 now available.
Added global variable for drawtype and calcfunction. Showtriggers now defaults to true.


Comment