From 1f14422ed097e9492edc393ca86ff5f20bad5778 Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Fri, 30 Oct 2015 07:49:35 +0100
Subject: [PATCH 01/23] update install docs

---
 README.md | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/README.md b/README.md
index 4a6ad8e..a17343e 100644
--- a/README.md
+++ b/README.md
@@ -30,6 +30,13 @@ Tested on:
 
     yum install collectd collectd-virt perl-Collectd
 ```
+
+* * if yum installation fails, install epel repo package (extras repo)
+
+``
+    yum install epel-release
+``
+
 * copy collectd config file (collectd.conf)
 
 * copy script "collect-libvirt-handler.pl" into /etc/zabbix/scripts/collectd-libvirt folder (with 755 perms)

From ddc3bc15e7c171721c421d0d4299d360b93d0d18 Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Fri, 30 Oct 2015 07:59:55 +0100
Subject: [PATCH 02/23] update install docs

---
 README.md | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index a17343e..ae7d627 100644
--- a/README.md
+++ b/README.md
@@ -18,6 +18,8 @@ Tested on:
 
 ### installation - Manual
 
+##### on monitored server (when you have kvm/libvirt)
+
 * install a configure zabbix-agent
 
 * copy file "zabbix-collectd.conf" into your zabbix include folder
@@ -37,7 +39,7 @@ Tested on:
     yum install epel-release
 ``
 
-* copy collectd config file (collectd.conf)
+* copy collectd config file (collectd.conf) into zabbix agent config folder (e.g. /etc/zabbix/zabbix_agentd.d)
 
 * copy script "collect-libvirt-handler.pl" into /etc/zabbix/scripts/collectd-libvirt folder (with 755 perms)
 
@@ -45,6 +47,10 @@ Tested on:
 
 * reboot zabbix-agent service
 
+##### on zabbix server
+
+* import template (xml file)
+
 ### installation - Automated
 
 * use puppet module/manifest [czhujer/puppet-zabbixagent](https://github.com/czhujer/puppet-zabbixagent#usage---example-manual-run)

From d435362c9442644ef487752b908c74f0eac1c56f Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Fri, 30 Oct 2015 08:09:24 +0100
Subject: [PATCH 03/23] update install docs

---
 README.md | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index ae7d627..e5cb4fd 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@ Tested on:
 
 ### installation - Manual
 
-##### on monitored server (when you have kvm/libvirt)
+##### on monitored server (where you have kvm/libvirt)
 
 * install a configure zabbix-agent
 
@@ -33,7 +33,7 @@ Tested on:
     yum install collectd collectd-virt perl-Collectd
 ```
 
-* * if yum installation fails, install epel repo package (extras repo)
+  * if yum installation fails, install epel repo package (extras repo)
 
 ``
     yum install epel-release

From 2bafa3cc1b22be819c565c633d548b3b69f653c2 Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Fri, 30 Oct 2015 08:17:24 +0100
Subject: [PATCH 04/23] fix formatting

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index e5cb4fd..03f8845 100644
--- a/README.md
+++ b/README.md
@@ -33,7 +33,7 @@ Tested on:
     yum install collectd collectd-virt perl-Collectd
 ```
 
-  * if yum installation fails, install epel repo package (extras repo)
+    * if yum installation fails, install epel repo package (extras repo)
 
 ``
     yum install epel-release

From 83a42d664c1d502cc01da52238500963b412c080 Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Fri, 30 Oct 2015 08:24:43 +0100
Subject: [PATCH 05/23] fix formatting

---
 README.md | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/README.md b/README.md
index 03f8845..f3a32b8 100644
--- a/README.md
+++ b/README.md
@@ -4,13 +4,11 @@ A Zabbix templates for libvirt stats
 
 Tested on:
 
-```
- Ubuntu 12.04 x86_64 with KVM (kernel 3.5.0-44), collectd 4.10
- Zabbix 2.0.x
+> Ubuntu 12.04 x86_64 with KVM (kernel 3.5.0-44), collectd 4.10
+> Zabbix 2.0.x
 
- CentOS 6.x X86_64, Collectd 4.10
- Zabbix 2.0.x
-```
+> CentOS 6.x X86_64, Collectd 4.10
+> Zabbix 2.0.x
 
 ### Authors
 * Patrik Majer <patrik.majer.pisek@gmail.com>
@@ -26,18 +24,18 @@ Tested on:
 
 * install collectd package(s) and perl modules
 
-```
+    ```sh
     apt-get install collectd
     apt-get install libregexp-common-perl
 
     yum install collectd collectd-virt perl-Collectd
-```
+    ```
 
-    * if yum installation fails, install epel repo package (extras repo)
+* * if yum installation fails, install epel repo package (extras repo)
 
-``
+    ```sh
     yum install epel-release
-``
+    ```
 
 * copy collectd config file (collectd.conf) into zabbix agent config folder (e.g. /etc/zabbix/zabbix_agentd.d)
 

From 136ada4c9da28a91094109c0e047e8d9ec46e89c Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Sun, 7 Feb 2016 16:08:50 +0100
Subject: [PATCH 06/23] fix intallation part

---
 README.md | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index f3a32b8..cf50a15 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ Tested on:
 
 * install a configure zabbix-agent
 
-* copy file "zabbix-collectd.conf" into your zabbix include folder
+* copy file "zabbix-collectd.conf" into zabbix agent config folder (e.g. /etc/zabbix/zabbix_agentd.d)
 
 * install collectd package(s) and perl modules
 
@@ -37,7 +37,8 @@ Tested on:
     yum install epel-release
     ```
 
-* copy collectd config file (collectd.conf) into zabbix agent config folder (e.g. /etc/zabbix/zabbix_agentd.d)
+* copy/rewrite collectd config file (collectd.conf) in /etc
+ or enable libvirt & unixsock plugins in collectd service
 
 * copy script "collect-libvirt-handler.pl" into /etc/zabbix/scripts/collectd-libvirt folder (with 755 perms)
 

From 1d2d0d3b700321bd095e34823017f677b988094e Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Sun, 7 Feb 2016 16:14:50 +0100
Subject: [PATCH 07/23] fix intallation part

---
 README.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/README.md b/README.md
index cf50a15..ac002b8 100644
--- a/README.md
+++ b/README.md
@@ -38,6 +38,7 @@ Tested on:
     ```
 
 * copy/rewrite collectd config file (collectd.conf) in /etc
+
  or enable libvirt & unixsock plugins in collectd service
 
 * copy script "collect-libvirt-handler.pl" into /etc/zabbix/scripts/collectd-libvirt folder (with 755 perms)

From fb2fbdce2e4fc9f45125f25be3892eb257048b0e Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Sun, 7 Feb 2016 16:15:35 +0100
Subject: [PATCH 08/23] fix formatting

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index ac002b8..5a24a23 100644
--- a/README.md
+++ b/README.md
@@ -39,7 +39,7 @@ Tested on:
 
 * copy/rewrite collectd config file (collectd.conf) in /etc
 
- or enable libvirt & unixsock plugins in collectd service
+* * or enable libvirt & unixsock plugins in collectd service
 
 * copy script "collect-libvirt-handler.pl" into /etc/zabbix/scripts/collectd-libvirt folder (with 755 perms)
 

From a1035b3bc9c855b4657882b63f24d679716fcdbf Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Sun, 7 Feb 2016 16:25:01 +0100
Subject: [PATCH 09/23] add readme for debbuging and deep dive

---
 README-DEBUGGING.md | 111 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 111 insertions(+)
 create mode 100644 README-DEBUGGING.md

diff --git a/README-DEBUGGING.md b/README-DEBUGGING.md
new file mode 100644
index 0000000..42e5098
--- /dev/null
+++ b/README-DEBUGGING.md
@@ -0,0 +1,111 @@
+# Zabbix Template Linux Collectd_libvirt - DEEP DIVE AND DEBUG MANUAL
+
+## How it works
+
+* zabbix-agent calls collect-libvirt-handler.pl script
+
+* collect-libvirt-handler.pl calls collectd service over unixsocket
+
+* * after transforms zabbix-item's names (keys) to libvirt's names (unixsocket format)
+
+* * after reads values and return data back to zabbix-agent
+
+If you have in zabbix name with key: collectd-libvirt.cpu["instance-00000841-virt_cpu_total"],
+zabbix runs external command: sudo /etc/zabbix/scripts/collectd-libvirt/collect-libvirt-handler.pl /var/run/collectd-unixsock GETVAL instance-00000841-virt_cpu_total
+and and should return number :)
+
+## Example workflow
+
+* You should be see in zabbix server this items
+
+```
+ collectd-libvirt.disk-ops-read[serve.lordcritical-disk-vda]
+ collectd-libvirt.disk-ops-write[serve.lordcritical-disk-vda]
+ collectd-libvirt.disk-oct-read[serve.lordcritical-disk-vda]
+ collectd-libvirt.disk-oct-write[serve.lordcritical-disk-vda]
+ collectd-libvirt.cpu[serve.lordcritical-virt_cpu_total]
+(and network items...)
+```
+
+* after this $command variable should be (...handler.pl):
+
+```
+GETVAL serve.lordcritical/libvirt/disk_ops-vda OPS-READ 
+GETVAL serve.lordcritical/libvirt/disk_ops-vda OPS-WRITE
+GETVAL serve.lordcritical/libvirt/disk_octets-vda OCT-READ
+GETVAL serve.lordcritical/libvirt/disk_octets-vda OCT-WRITE
+GETVAL serve.lordcritical/libvirt/virt_cpu_total
+``
+
+* and into collectd unixsocket arrive queries
+
+GETVAL serve.lordcritical/libvirt/disk_ops-vda
+GETVAL serve.lordcritical/libvirt/disk_octets-vda
+GETVAL serve.lordcritical/libvirt/virt_cpu_total
+
+## Example of Discovery results
+
+https://github.com/czhujer/Zabbix-Template-Linux-Collectd_libvirt/blob/master/docs-examples/example-discovery-result.md
+
+
+## DEBUG
+
+1. install template https://github.com/czhujer/Zabbix-Template-Linux-Collectd_libvirt
+
+2. check if script collect-libvirt-handler.pl works
+
+3. uncomment line 45 (print "DEBUG: command: " . $command . " val: " . $val . " \n";)
+
+4. check results ..
+
+
+~~~
+with zabbix key: 	collectd-libvirt.cpu["instance-00000841-virt_cpu_total"]
+debug output shlould by: 
+DEBUG: command: GETVAL instance-00000841/libvirt/virt_cpu_total val: instance-00000841/libvirt/virt_cpu_total
+2000000
+~~~
+
+5. if dont have, download exmaple script for collectd unixsocket communication..
+
+  (wget https://raw.githubusercontent.com/collectd/collectd/master/contrib/cussh.pl)
+
+6. run example script
+
+  [root@localhost]# ./cussh.pl or ./cussh.pl /var/run/collectd-unixsock
+
+7. send command from $command value into cussh shel..
+
+cussh> GETVAL instance-00000841/libvirt/virt_cpu_total
+        ns: 2000000
+
+8. check if this number is same as returns collect-libvirt-handler.pl
+
+
+DEBUG items name
+
+simillar like a DEBUG
+
+7. run commnad "LISTVAL" in cussh shel..
+
+cussh> LISTVAL
+
+1413985396 instance-00000935/libvirt/disk_octets-vda
+1413985396 instance-00000935/libvirt/disk_ops-vda
+1413985396 instance-00000935/libvirt/if_dropped-tap869d29b8-08
+1413985396 instance-00000935/libvirt/if_errors-tap869d29b8-08
+1413985396 instance-00000935/libvirt/if_octets-tap869d29b8-08
+1413985396 instance-00000935/libvirt/if_packets-tap869d29b8-08
+1413985396 instance-00000935/libvirt/virt_cpu_total
+1413985396 instance-00000935/libvirt/virt_vcpu-0
+1413985396 instance-00000935/libvirt/virt_vcpu-1
+
+8. modify script collect-libvirt-handler.pl like that, so print to the same things as you see in LISTVAL part...
+
+LINES 21 - 24 is for "cpu_total"
+
+LINES 25 - 33 is for "disk stats"
+
+LINES 34 - 41 is for "networks stats"
+
+

From d3995cbff7699226f8977a4e517562730c80e201 Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Sun, 7 Feb 2016 16:25:48 +0100
Subject: [PATCH 10/23] fix formatting

---
 README-DEBUGGING.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README-DEBUGGING.md b/README-DEBUGGING.md
index 42e5098..1d0b71c 100644
--- a/README-DEBUGGING.md
+++ b/README-DEBUGGING.md
@@ -35,7 +35,7 @@ GETVAL serve.lordcritical/libvirt/disk_ops-vda OPS-WRITE
 GETVAL serve.lordcritical/libvirt/disk_octets-vda OCT-READ
 GETVAL serve.lordcritical/libvirt/disk_octets-vda OCT-WRITE
 GETVAL serve.lordcritical/libvirt/virt_cpu_total
-``
+```
 
 * and into collectd unixsocket arrive queries
 

From d6ef3b22f58baa43ef7262051c457c377e79d9da Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Sun, 7 Feb 2016 16:26:09 +0100
Subject: [PATCH 11/23] fix formatting

---
 README-DEBUGGING.md | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/README-DEBUGGING.md b/README-DEBUGGING.md
index 1d0b71c..6ab9f73 100644
--- a/README-DEBUGGING.md
+++ b/README-DEBUGGING.md
@@ -39,9 +39,11 @@ GETVAL serve.lordcritical/libvirt/virt_cpu_total
 
 * and into collectd unixsocket arrive queries
 
+```
 GETVAL serve.lordcritical/libvirt/disk_ops-vda
 GETVAL serve.lordcritical/libvirt/disk_octets-vda
 GETVAL serve.lordcritical/libvirt/virt_cpu_total
+```
 
 ## Example of Discovery results
 

From 8f711ec99d008e362d7f911d18411d264b1cbb7a Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Sun, 7 Feb 2016 16:26:42 +0100
Subject: [PATCH 12/23] fix formatting

---
 README-DEBUGGING.md | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/README-DEBUGGING.md b/README-DEBUGGING.md
index 6ab9f73..a68648e 100644
--- a/README-DEBUGGING.md
+++ b/README-DEBUGGING.md
@@ -84,7 +84,7 @@ cussh> GETVAL instance-00000841/libvirt/virt_cpu_total
 8. check if this number is same as returns collect-libvirt-handler.pl
 
 
-DEBUG items name
+### DEBUG items name
 
 simillar like a DEBUG
 
@@ -109,5 +109,3 @@ LINES 21 - 24 is for "cpu_total"
 LINES 25 - 33 is for "disk stats"
 
 LINES 34 - 41 is for "networks stats"
-
-

From 7da04c3b2a5d00e93009fb0222954f122734b8ea Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Sun, 7 Feb 2016 16:27:51 +0100
Subject: [PATCH 13/23] fix formatting

---
 README-DEBUGGING.md | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/README-DEBUGGING.md b/README-DEBUGGING.md
index a68648e..354e222 100644
--- a/README-DEBUGGING.md
+++ b/README-DEBUGGING.md
@@ -70,16 +70,22 @@ DEBUG: command: GETVAL instance-00000841/libvirt/virt_cpu_total val: instance-00
 
 5. if dont have, download exmaple script for collectd unixsocket communication..
 
-  (wget https://raw.githubusercontent.com/collectd/collectd/master/contrib/cussh.pl)
+```
+  [root@localhost]# wget https://raw.githubusercontent.com/collectd/collectd/master/contrib/cussh.pl
+```
 
 6. run example script
 
+```
   [root@localhost]# ./cussh.pl or ./cussh.pl /var/run/collectd-unixsock
+```
 
 7. send command from $command value into cussh shel..
 
+```
 cussh> GETVAL instance-00000841/libvirt/virt_cpu_total
         ns: 2000000
+```
 
 8. check if this number is same as returns collect-libvirt-handler.pl
 

From c016b0f55fec4f29fbaa2f0ae392eb94cf32e9ba Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Sun, 7 Feb 2016 16:28:50 +0100
Subject: [PATCH 14/23] fix formatting

---
 README-DEBUGGING.md | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/README-DEBUGGING.md b/README-DEBUGGING.md
index 354e222..eaacbef 100644
--- a/README-DEBUGGING.md
+++ b/README-DEBUGGING.md
@@ -52,13 +52,13 @@ https://github.com/czhujer/Zabbix-Template-Linux-Collectd_libvirt/blob/master/do
 
 ## DEBUG
 
-1. install template https://github.com/czhujer/Zabbix-Template-Linux-Collectd_libvirt
+* install template https://github.com/czhujer/Zabbix-Template-Linux-Collectd_libvirt
 
-2. check if script collect-libvirt-handler.pl works
+* check if script collect-libvirt-handler.pl works
 
-3. uncomment line 45 (print "DEBUG: command: " . $command . " val: " . $val . " \n";)
+* uncomment line 45 (print "DEBUG: command: " . $command . " val: " . $val . " \n";)
 
-4. check results ..
+* check results ..
 
 
 ~~~
@@ -68,33 +68,33 @@ DEBUG: command: GETVAL instance-00000841/libvirt/virt_cpu_total val: instance-00
 2000000
 ~~~
 
-5. if dont have, download exmaple script for collectd unixsocket communication..
+* if dont have, download exmaple script for collectd unixsocket communication..
 
 ```
   [root@localhost]# wget https://raw.githubusercontent.com/collectd/collectd/master/contrib/cussh.pl
 ```
 
-6. run example script
+* run example script
 
 ```
   [root@localhost]# ./cussh.pl or ./cussh.pl /var/run/collectd-unixsock
 ```
 
-7. send command from $command value into cussh shel..
+* send command from $command value into cussh shel..
 
 ```
 cussh> GETVAL instance-00000841/libvirt/virt_cpu_total
         ns: 2000000
 ```
 
-8. check if this number is same as returns collect-libvirt-handler.pl
+* check if this number is same as returns collect-libvirt-handler.pl
 
 
 ### DEBUG items name
 
 simillar like a DEBUG
 
-7. run commnad "LISTVAL" in cussh shel..
+* run commnad "LISTVAL" in cussh shel..
 
 cussh> LISTVAL
 
@@ -108,7 +108,7 @@ cussh> LISTVAL
 1413985396 instance-00000935/libvirt/virt_vcpu-0
 1413985396 instance-00000935/libvirt/virt_vcpu-1
 
-8. modify script collect-libvirt-handler.pl like that, so print to the same things as you see in LISTVAL part...
+* modify script collect-libvirt-handler.pl like that, so print to the same things as you see in LISTVAL part...
 
 LINES 21 - 24 is for "cpu_total"
 

From 262eec992910a197c6bbd4041b2f963e6aa3090d Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Sun, 7 Feb 2016 16:29:58 +0100
Subject: [PATCH 15/23] fix formatting

---
 README-DEBUGGING.md | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/README-DEBUGGING.md b/README-DEBUGGING.md
index eaacbef..05135f6 100644
--- a/README-DEBUGGING.md
+++ b/README-DEBUGGING.md
@@ -56,7 +56,9 @@ https://github.com/czhujer/Zabbix-Template-Linux-Collectd_libvirt/blob/master/do
 
 * check if script collect-libvirt-handler.pl works
 
-* uncomment line 45 (print "DEBUG: command: " . $command . " val: " . $val . " \n";)
+* uncomment line 45
+
+  (print "DEBUG: command: " . $command . " val: " . $val . " \n";)
 
 * check results ..
 
@@ -96,6 +98,7 @@ simillar like a DEBUG
 
 * run commnad "LISTVAL" in cussh shel..
 
+```
 cussh> LISTVAL
 
 1413985396 instance-00000935/libvirt/disk_octets-vda
@@ -107,6 +110,7 @@ cussh> LISTVAL
 1413985396 instance-00000935/libvirt/virt_cpu_total
 1413985396 instance-00000935/libvirt/virt_vcpu-0
 1413985396 instance-00000935/libvirt/virt_vcpu-1
+```
 
 * modify script collect-libvirt-handler.pl like that, so print to the same things as you see in LISTVAL part...
 

From daaca9ef91e2f8b6e97a393903392b3022a0fef5 Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Fri, 26 Feb 2016 12:08:33 +0100
Subject: [PATCH 16/23] fix perl variable warning

---
 scripts/collect-libvirt-handler.pl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/collect-libvirt-handler.pl b/scripts/collect-libvirt-handler.pl
index 6b99f5e..db6eb0e 100755
--- a/scripts/collect-libvirt-handler.pl
+++ b/scripts/collect-libvirt-handler.pl
@@ -9,10 +9,10 @@
 	my $path = $ARGV[0] || "/var/run/collectd-unixsock";
 	my $command = $ARGV[1] || "LISTVAL";
 	my @vals;
-	our $val = $ARGV[2];
+	our $val = $ARGV[2] \\ "undef";
 	our $val_type = $ARGV[3] || "undef";
 
-	if( $command eq "LISTVAL" and $val eq ""){
+	if( $command eq "LISTVAL" and $val eq "undef"){
 	    $val = "ALL"
 	}
 

From 5fd0c6b22bf97372b01ffbc6974e37d01e660783 Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Fri, 26 Feb 2016 12:18:52 +0100
Subject: [PATCH 17/23] fix merging

---
 README.md | 2 --
 1 file changed, 2 deletions(-)

diff --git a/README.md b/README.md
index 5576d1d..5a24a23 100644
--- a/README.md
+++ b/README.md
@@ -37,8 +37,6 @@ Tested on:
     yum install epel-release
     ```
 
-* copy collectd config file (collectd.conf) into zabbix agent config folder (e.g. /etc/zabbix/zabbix_agentd.d)
-=======
 * copy/rewrite collectd config file (collectd.conf) in /etc
 
 * * or enable libvirt & unixsock plugins in collectd service

From 27e188643d9889c7fbca23e57ec19d7abb2e3056 Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Fri, 26 Feb 2016 14:07:23 +0100
Subject: [PATCH 18/23] fix syntax

---
 scripts/collect-libvirt-handler.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/collect-libvirt-handler.pl b/scripts/collect-libvirt-handler.pl
index db6eb0e..ce7a3a0 100755
--- a/scripts/collect-libvirt-handler.pl
+++ b/scripts/collect-libvirt-handler.pl
@@ -9,7 +9,7 @@
 	my $path = $ARGV[0] || "/var/run/collectd-unixsock";
 	my $command = $ARGV[1] || "LISTVAL";
 	my @vals;
-	our $val = $ARGV[2] \\ "undef";
+	our $val = $ARGV[2] || "undef";
 	our $val_type = $ARGV[3] || "undef";
 
 	if( $command eq "LISTVAL" and $val eq "undef"){

From a838c52a7f0d1c0143524147ce9f01040b3bfffb Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Fri, 26 Feb 2016 15:18:18 +0100
Subject: [PATCH 19/23] fix app assignment in template

---
 Template_Linux_Collectd_libvirt.xml | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/Template_Linux_Collectd_libvirt.xml b/Template_Linux_Collectd_libvirt.xml
index 46fc476..f054338 100644
--- a/Template_Linux_Collectd_libvirt.xml
+++ b/Template_Linux_Collectd_libvirt.xml
@@ -94,9 +94,6 @@
                                 <application>
                                     <name>Libvirt - disk octets stats</name>
                                 </application>
-                                <application>
-                                    <name>Libvirt - Disk operations stats</name>
-                                </application>
                             </applications>
                             <valuemap/>
                         </item_prototype>

From 96e5bde1e6bf4192dfa1bdaf7774081193ea6f20 Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Fri, 26 Feb 2016 15:30:19 +0100
Subject: [PATCH 20/23] update testing part

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 5a24a23..5dd3e64 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
 
 A Zabbix templates for libvirt stats
 
-Tested on:
+versions 1.2 and lower were tested on:
 
 > Ubuntu 12.04 x86_64 with KVM (kernel 3.5.0-44), collectd 4.10
 > Zabbix 2.0.x

From 913fe9051cd3917faa8d198b3fb963cd33c856ac Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Fri, 26 Feb 2016 15:33:14 +0100
Subject: [PATCH 21/23] add test script for collecd v5.5

---
 scripts/collect-libvirt-handler-v5.pl | 447 ++++++++++++++++++++++++++
 1 file changed, 447 insertions(+)
 create mode 100755 scripts/collect-libvirt-handler-v5.pl

diff --git a/scripts/collect-libvirt-handler-v5.pl b/scripts/collect-libvirt-handler-v5.pl
new file mode 100755
index 0000000..2306919
--- /dev/null
+++ b/scripts/collect-libvirt-handler-v5.pl
@@ -0,0 +1,447 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Collectd::Unixsock();
+
+{ # main
+	my $path = $ARGV[0] || "/var/run/collectd-unixsock";
+	my $command = $ARGV[1] || "LISTVAL";
+	my @vals;
+	our $val = $ARGV[2] || "undef";
+	our $val_type = $ARGV[3] || "undef";
+        our $collectd_version;
+
+        $collectd_version = `collectd -h |grep \'http://\' | sed \'s/\^.*[^0-9]\\([0-9]*\\.[0-9]*\\.[0-9]*\\).*\$/\\1/\' | tr -d '\n'`;
+
+#        print "INFO: collectd version: " . $collectd_version . "\n";
+
+	if( $command eq "LISTVAL" and $val eq "undef"){
+	    $val = "ALL"
+	}
+
+	if( $command eq "GETVAL"){
+	
+	    if( $val =~ /^.*-virt_cpu_total/ ){
+		@vals = split(/-virt/, $val);
+		
+		if( $collectd_version =~ /5.5/ ){
+		   $val = $vals[0] . "/virt-" . $vals[0] . "/virt" . $vals[1]
+		}
+		else{
+		   $val = $vals[0] . "/libvirt/" . "virt" . $vals[1]
+		}
+	    }
+	    elsif($val =~ /^.*-disk-/ and $val_type =~ /^OPS/){
+		@vals = split(/-disk/, $val);
+		
+		if( $collectd_version =~ /5.5/ ){
+		  $val = $vals[0] . "/virt-" . $vals[0] . "/disk_ops" .$vals[1]
+		}
+		else {
+		  $val = $vals[0] . "/libvirt/disk_ops" .$vals[1]
+		}
+	    }
+	    elsif($val =~ /^.*-disk-/ and $val_type =~ /^OCT/){
+		@vals = split(/-disk/, $val);
+		
+		if( $collectd_version =~ /5.5/ ){
+		    $val = $vals[0] . "/virt-" . $vals[0] . "/disk_octets" .$vals[1]
+		}
+		else {
+		    $val = $vals[0] . "/libvirt/disk_octets" .$vals[1]
+		}
+	    }
+	    elsif($val =~ /^.*-if-/ and $val_type =~ /^NET-PACKETS/){
+		@vals = split(/-if/, $val);
+		if( $collectd_version =~ /5.5/ ){
+		    $val = $vals[0] . "/virt-" . $vals[0] . "/if_packets" . $vals[1]
+		}
+		else {
+		    $val = $vals[0] . "/libvirt/if_packets" . $vals[1]
+		}
+	    }
+	    elsif($val =~ /^.*-if-/ and $val_type =~ /^NET-OCTETS/){
+		@vals = split(/-if/, $val);
+		if( $collectd_version =~ /5.5/ ){
+		    $val = $vals[0] . "/virt-" . $vals[0] . "/if_octets" .$vals[1]
+		}
+		else{
+		    $val = $vals[0] . "/libvirt/if_octets" .$vals[1]
+		}
+	    }
+	    $command .= " " . $val;
+	    
+	    #debug 
+	    #print "DEBUG: command: " . $command . " val: " . $val . " \n";
+	}
+
+	my $sock = Collectd::Unixsock->new($path);
+
+        my $cmds = {
+                HELP    => \&cmd_help,
+                PUTVAL  => \&putval,
+                GETVAL  => \&getval,
+                GETTHRESHOLD  => \&getthreshold,
+                FLUSH   => \&flush,
+                LISTVAL => \&listval,
+                PUTNOTIF => \&putnotif,
+        };
+
+
+	if (! $sock) {
+		print STDERR "Unable to connect to $path!\n";
+		exit 1;
+	}
+
+	my $line = $command;
+
+	last if (! $line);
+
+	chomp $line;
+
+	last if ($line =~ m/^quit$/i);
+
+	my ($cmd) = $line =~ m/^(\w+)\s*/;
+	$line = $';
+
+	next if (! $cmd);
+	$cmd = uc $cmd;
+
+	my $f = undef;
+	if (defined $cmds->{$cmd}) {
+		$f = $cmds->{$cmd};
+	}
+	else {
+		print STDERR "ERROR: Unknown command $cmd!\n";
+		next;
+	}
+
+	if (! $f->($sock, $line)) {
+	    print STDERR "ERROR: Command failed!\n";
+	    next;
+	}
+
+	$sock->destroy();
+	exit 0;
+}
+
+sub tokenize {
+        my $line     = shift || return;
+        my $line_ptr = $line;
+        my @line     = ();
+
+        my $token_pattern = qr/[^"\s]+|"[^"]+"/;
+
+        while (my ($token) = $line_ptr =~ m/^($token_pattern)\s+/) {
+                $line_ptr = $';
+                push @line, $token;
+        }
+
+        if ($line_ptr =~ m/^$token_pattern$/) {
+                push @line, $line_ptr;
+        }
+        else {
+                my ($token) = split m/ /, $line_ptr, 1;
+                print STDERR "Failed to parse line: $line\n";
+                print STDERR "Parse error near token \"$token\".\n";
+                return;
+        }
+
+        foreach my $l (@line) {
+                if ($l =~ m/^"(.*)"$/) {
+                        $l = $1;
+                }
+        }
+        return @line;
+}
+
+sub getid {
+        my $string = shift || return;
+
+        my ($h, $p, $pi, $t, $ti) =
+                $string =~ m#^([^/]+)/([^/-]+)(?:-([^/]+))?/([^/-]+)(?:-([^/]+))?\s*#;
+        $string = $';
+
+        return if ((! $h) || (! $p) || (! $t));
+
+        my %id = ();
+
+        ($id{'host'}, $id{'plugin'}, $id{'type'}) = ($h, $p, $t);
+
+        $id{'plugin_instance'} = $pi if defined ($pi);
+        $id{'type_instance'} = $ti if defined ($ti);
+        return \%id;
+}
+
+sub putid {
+        my $ident = shift || return;
+
+        my $string;
+
+	our $val;
+
+        $string = $ident->{'host'} . "/" . $ident->{'plugin'};
+
+        if (defined $ident->{'plugin_instance'}) {
+                $string .= "-" . $ident->{'plugin_instance'};
+        }
+
+        $string .= "/" . $ident->{'type'};
+
+        if (defined $ident->{'type_instance'}) {
+                $string .= "-" . $ident->{'type_instance'};
+        }
+
+	if( $val eq "ALL"){
+    	    return $string . $/;
+	}
+	elsif( $ident->{'type'} eq "virt_cpu_total" and $val eq "CPU"){
+    	    return $string . $/;
+	}
+}
+
+sub putidjson {
+        my $ident = shift || return;
+        my $string;
+        my $stringjson;
+#        my $stringjson5;
+	our $val;
+#	our $collectd_version;
+
+        #debug dumping
+        sub print_hash {
+            my $href = shift;
+            print "$_\t=> $href->{$_}\n" for keys %{$href};
+        }
+        #print_hash($ident);
+        #end of debug dumping
+
+        $string = $ident->{'host'};
+
+	if( $val eq "ALL"){
+	    $string .= "-" . $ident->{'plugin'};
+	}
+
+        if (defined $ident->{'plugin_instance'} and $ident->{'plugin'} ne "virt") {
+                $string .= "-" . $ident->{'plugin_instance'};
+        }
+
+	if ($ident->{'plugin'} eq "libvirt" and $ident->{'type'} =~ /^disk/ and $val eq "LIBVIRT-DISK"){
+	    $ident->{'type'} =~ s/_ops//;
+            $string .= "-" . $ident->{'type'};
+	}
+	elsif ($ident->{'plugin'} eq "libvirt" and $ident->{'type'} =~ /^if/ and $val eq "LIBVIRT-NET") {
+	    $ident->{'type'} =~ s/_packets//;
+    	    $string .= "-" . $ident->{'type'};
+	}
+	elsif ($ident->{'plugin'} eq "virt" and $ident->{'type'} =~ /^disk/ and $val eq "LIBVIRT-DISK"){
+	    $ident->{'type'} =~ s/_ops//;
+            $string .= "-" . $ident->{'type'};
+	}
+	elsif ($ident->{'plugin'} eq "virt" and $ident->{'type'} =~ /^if/ and $val eq "LIBVIRT-NET") {
+	    $ident->{'type'} =~ s/_packets//;
+    	    $string .= "-" . $ident->{'type'};
+	}
+	else{	
+            $string .= "-" . $ident->{'type'};
+	}
+
+        if (defined $ident->{'type_instance'}) {
+                $string .= "-" . $ident->{'type_instance'};
+        }
+
+	$stringjson = "{#NAME}\":\"" . $string . "\"";
+
+	if( $val eq "ALL"){
+    	    return $stringjson;
+	}
+	elsif( $ident->{'plugin'} eq "libvirt" and $ident->{'type'} eq "virt_cpu_total" and $val eq "LIBVIRT-CPU"){
+    	    return $stringjson;
+	}
+	elsif( $ident->{'plugin'} eq "libvirt" and $ident->{'type'} =~ /^disk$/ and $val eq "LIBVIRT-DISK"){
+    	    return $stringjson;
+	}
+	elsif( $ident->{'plugin'} eq "libvirt" and $ident->{'type'} =~ /^if$/ and $val eq "LIBVIRT-NET"){
+    	    return $stringjson;
+	}
+	elsif( $ident->{'plugin'} eq "virt" and $ident->{'type'} eq "virt_cpu_total" and $val eq "LIBVIRT-CPU"){
+    	    return $stringjson;
+	}
+	elsif( $ident->{'plugin'} eq "virt" and $ident->{'type'} =~ /^disk$/ and $val eq "LIBVIRT-DISK"){
+    	    return $stringjson;
+	}
+	elsif( $ident->{'plugin'} eq "virt" and $ident->{'type'} =~ /^if$/ and $val eq "LIBVIRT-NET"){
+    	    return $stringjson;
+	}
+	# unknown plugin / known plugin not found
+}
+
+sub listval {
+	my $sock = shift || return;
+	my $line = shift;
+
+	my @res;
+
+	if ($line ne "") {
+		print STDERR "Synopsis: LISTVAL" . $/;
+		return;
+	}
+
+	@res = $sock->listval();
+
+	if (! @res) {
+	    print STDERR "socket error: " . $sock->{'error'} . $/;
+	    return;
+	}
+
+	my $firstline = 1;
+
+	print "{\n\t\"data\":[\n\n";
+
+	foreach my $ident (@res) {
+
+      my $rs = putidjson($ident);
+	   
+	   if(length($rs) > 0){
+
+	   	print "\t,\n" if not $firstline;
+	   	$firstline = 0;
+	   	print "\t{\n";
+
+	   	print "\t\t\"" . putidjson($ident) . "\n";
+
+	   	print "\t}\n";
+	   } #end of if
+
+	} #end of foreach
+
+	print "\n\t]\n";
+	print "}\n";
+
+	return 1;
+}
+
+sub getval {
+        my $sock = shift || return;
+        my $line = shift || return;
+
+        my @line = tokenize($line);
+
+        my $id;
+        my $vals;
+
+	my $err_msg;
+	our $val_type;
+
+        if (! @line) {
+                return;
+        }
+
+        if (scalar(@line) < 1) {
+                print STDERR "Synopsis: GETVAL <id>" . $/;
+                return;
+        }
+
+        $id = getid($line[0]);
+
+        if (! $id) {
+                print STDERR "Invalid id \"$line[0]\"." . $/;
+                return;
+        }
+
+        $vals = $sock->getval(%$id);
+
+        if (! $vals) {
+
+		$err_msg = $sock->{'error'};
+
+		if ("$err_msg" eq "No such value") {
+		    print "0" .$/;
+		    return 1;
+		}
+#		else
+		{
+#            	    print STDERR "socket error: " . $sock->{'error'} . $/;
+            	    print STDERR "socket error: " . $sock->{'error'} . $/;
+		    return;
+                }
+        }
+
+        foreach my $key (keys %$vals) {
+
+	    #debug
+	    #print $line[0] . "\n";
+
+	    if( $line[0] =~ /^.*\/.*virt.*\/virt_cpu_total/ ){
+                print "$vals->{$key}\n";
+	    }
+	    elsif( $line[0] =~ /^.*\/.*virt.*\/disk_ops/ ){
+
+		if($val_type eq "OPS-READ" and $key eq "read"){
+            	    print "$vals->{$key}\n";
+		}
+		elsif($val_type eq "OPS-WRITE" and $key eq "write"){
+            	    print "$vals->{$key}\n";
+		}
+		elsif($val_type eq "OPS"){
+                    print "\t$key: $vals->{$key}\n";
+		}
+	    }
+	    elsif($line[0] =~ /^.*\/.*virt.*\/disk_octets/){
+	    
+		#debug
+		#print "DEBUG: disk_octets options ..." . $/;
+		
+		if($val_type eq "OCT-READ" and $key eq "read"){
+            	    print "$vals->{$key}\n";
+		}
+		elsif($val_type eq "OCT-WRITE" and $key eq "write"){
+            	    print "$vals->{$key}\n";
+		}
+		elsif($val_type eq "OCT"){
+                    print "\t$key: $vals->{$key}\n";
+		}
+
+	    }
+	    elsif($line[0] =~ /^.*\/.*virt.*\/if_packets/){
+
+		#debug
+		#print "DEBUG: if_packets options ..." . $/;
+		
+		if($val_type eq "NET-PACKETS-RX" and $key eq "rx"){
+            	    print "$vals->{$key}\n";
+		}
+		elsif($val_type eq "NET-PACKETS-TX" and $key eq "tx"){
+            	    print "$vals->{$key}\n";
+		}
+		elsif($val_type eq "NET-PACKETS"){
+                    print "\t$key: $vals->{$key}\n";
+		}
+		
+	    }
+	    elsif($line[0] =~ /^.*\/.*virt.*\/if_octets/){
+
+		#debug
+		#print "DEBUG: if_octets options ..." . $/;
+		
+		if($val_type eq "NET-OCTETS-RX" and $key eq "rx"){
+            	    print "$vals->{$key}\n";
+		}
+		elsif($val_type eq "NET-OCTETS-TX" and $key eq "tx"){
+            	    print "$vals->{$key}\n";
+		}
+		elsif($val_type eq "NET-OCTETS"){
+                    print "\t$key: $vals->{$key}\n";
+		}
+		
+	    }
+	    else{
+                print "\t$key: $vals->{$key}\n";
+	    }
+        }
+        return 1;
+}
+
+

From 67b1952931e6b6b870e2f6c03477eedef73045d7 Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Sat, 27 Feb 2016 09:14:48 +0100
Subject: [PATCH 22/23] set new script as default

---
 scripts/collect-libvirt-handler-v5.pl | 447 --------------------------
 scripts/collect-libvirt-handler.pl    |  86 ++++-
 2 files changed, 72 insertions(+), 461 deletions(-)
 delete mode 100755 scripts/collect-libvirt-handler-v5.pl

diff --git a/scripts/collect-libvirt-handler-v5.pl b/scripts/collect-libvirt-handler-v5.pl
deleted file mode 100755
index 2306919..0000000
--- a/scripts/collect-libvirt-handler-v5.pl
+++ /dev/null
@@ -1,447 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-
-use Collectd::Unixsock();
-
-{ # main
-	my $path = $ARGV[0] || "/var/run/collectd-unixsock";
-	my $command = $ARGV[1] || "LISTVAL";
-	my @vals;
-	our $val = $ARGV[2] || "undef";
-	our $val_type = $ARGV[3] || "undef";
-        our $collectd_version;
-
-        $collectd_version = `collectd -h |grep \'http://\' | sed \'s/\^.*[^0-9]\\([0-9]*\\.[0-9]*\\.[0-9]*\\).*\$/\\1/\' | tr -d '\n'`;
-
-#        print "INFO: collectd version: " . $collectd_version . "\n";
-
-	if( $command eq "LISTVAL" and $val eq "undef"){
-	    $val = "ALL"
-	}
-
-	if( $command eq "GETVAL"){
-	
-	    if( $val =~ /^.*-virt_cpu_total/ ){
-		@vals = split(/-virt/, $val);
-		
-		if( $collectd_version =~ /5.5/ ){
-		   $val = $vals[0] . "/virt-" . $vals[0] . "/virt" . $vals[1]
-		}
-		else{
-		   $val = $vals[0] . "/libvirt/" . "virt" . $vals[1]
-		}
-	    }
-	    elsif($val =~ /^.*-disk-/ and $val_type =~ /^OPS/){
-		@vals = split(/-disk/, $val);
-		
-		if( $collectd_version =~ /5.5/ ){
-		  $val = $vals[0] . "/virt-" . $vals[0] . "/disk_ops" .$vals[1]
-		}
-		else {
-		  $val = $vals[0] . "/libvirt/disk_ops" .$vals[1]
-		}
-	    }
-	    elsif($val =~ /^.*-disk-/ and $val_type =~ /^OCT/){
-		@vals = split(/-disk/, $val);
-		
-		if( $collectd_version =~ /5.5/ ){
-		    $val = $vals[0] . "/virt-" . $vals[0] . "/disk_octets" .$vals[1]
-		}
-		else {
-		    $val = $vals[0] . "/libvirt/disk_octets" .$vals[1]
-		}
-	    }
-	    elsif($val =~ /^.*-if-/ and $val_type =~ /^NET-PACKETS/){
-		@vals = split(/-if/, $val);
-		if( $collectd_version =~ /5.5/ ){
-		    $val = $vals[0] . "/virt-" . $vals[0] . "/if_packets" . $vals[1]
-		}
-		else {
-		    $val = $vals[0] . "/libvirt/if_packets" . $vals[1]
-		}
-	    }
-	    elsif($val =~ /^.*-if-/ and $val_type =~ /^NET-OCTETS/){
-		@vals = split(/-if/, $val);
-		if( $collectd_version =~ /5.5/ ){
-		    $val = $vals[0] . "/virt-" . $vals[0] . "/if_octets" .$vals[1]
-		}
-		else{
-		    $val = $vals[0] . "/libvirt/if_octets" .$vals[1]
-		}
-	    }
-	    $command .= " " . $val;
-	    
-	    #debug 
-	    #print "DEBUG: command: " . $command . " val: " . $val . " \n";
-	}
-
-	my $sock = Collectd::Unixsock->new($path);
-
-        my $cmds = {
-                HELP    => \&cmd_help,
-                PUTVAL  => \&putval,
-                GETVAL  => \&getval,
-                GETTHRESHOLD  => \&getthreshold,
-                FLUSH   => \&flush,
-                LISTVAL => \&listval,
-                PUTNOTIF => \&putnotif,
-        };
-
-
-	if (! $sock) {
-		print STDERR "Unable to connect to $path!\n";
-		exit 1;
-	}
-
-	my $line = $command;
-
-	last if (! $line);
-
-	chomp $line;
-
-	last if ($line =~ m/^quit$/i);
-
-	my ($cmd) = $line =~ m/^(\w+)\s*/;
-	$line = $';
-
-	next if (! $cmd);
-	$cmd = uc $cmd;
-
-	my $f = undef;
-	if (defined $cmds->{$cmd}) {
-		$f = $cmds->{$cmd};
-	}
-	else {
-		print STDERR "ERROR: Unknown command $cmd!\n";
-		next;
-	}
-
-	if (! $f->($sock, $line)) {
-	    print STDERR "ERROR: Command failed!\n";
-	    next;
-	}
-
-	$sock->destroy();
-	exit 0;
-}
-
-sub tokenize {
-        my $line     = shift || return;
-        my $line_ptr = $line;
-        my @line     = ();
-
-        my $token_pattern = qr/[^"\s]+|"[^"]+"/;
-
-        while (my ($token) = $line_ptr =~ m/^($token_pattern)\s+/) {
-                $line_ptr = $';
-                push @line, $token;
-        }
-
-        if ($line_ptr =~ m/^$token_pattern$/) {
-                push @line, $line_ptr;
-        }
-        else {
-                my ($token) = split m/ /, $line_ptr, 1;
-                print STDERR "Failed to parse line: $line\n";
-                print STDERR "Parse error near token \"$token\".\n";
-                return;
-        }
-
-        foreach my $l (@line) {
-                if ($l =~ m/^"(.*)"$/) {
-                        $l = $1;
-                }
-        }
-        return @line;
-}
-
-sub getid {
-        my $string = shift || return;
-
-        my ($h, $p, $pi, $t, $ti) =
-                $string =~ m#^([^/]+)/([^/-]+)(?:-([^/]+))?/([^/-]+)(?:-([^/]+))?\s*#;
-        $string = $';
-
-        return if ((! $h) || (! $p) || (! $t));
-
-        my %id = ();
-
-        ($id{'host'}, $id{'plugin'}, $id{'type'}) = ($h, $p, $t);
-
-        $id{'plugin_instance'} = $pi if defined ($pi);
-        $id{'type_instance'} = $ti if defined ($ti);
-        return \%id;
-}
-
-sub putid {
-        my $ident = shift || return;
-
-        my $string;
-
-	our $val;
-
-        $string = $ident->{'host'} . "/" . $ident->{'plugin'};
-
-        if (defined $ident->{'plugin_instance'}) {
-                $string .= "-" . $ident->{'plugin_instance'};
-        }
-
-        $string .= "/" . $ident->{'type'};
-
-        if (defined $ident->{'type_instance'}) {
-                $string .= "-" . $ident->{'type_instance'};
-        }
-
-	if( $val eq "ALL"){
-    	    return $string . $/;
-	}
-	elsif( $ident->{'type'} eq "virt_cpu_total" and $val eq "CPU"){
-    	    return $string . $/;
-	}
-}
-
-sub putidjson {
-        my $ident = shift || return;
-        my $string;
-        my $stringjson;
-#        my $stringjson5;
-	our $val;
-#	our $collectd_version;
-
-        #debug dumping
-        sub print_hash {
-            my $href = shift;
-            print "$_\t=> $href->{$_}\n" for keys %{$href};
-        }
-        #print_hash($ident);
-        #end of debug dumping
-
-        $string = $ident->{'host'};
-
-	if( $val eq "ALL"){
-	    $string .= "-" . $ident->{'plugin'};
-	}
-
-        if (defined $ident->{'plugin_instance'} and $ident->{'plugin'} ne "virt") {
-                $string .= "-" . $ident->{'plugin_instance'};
-        }
-
-	if ($ident->{'plugin'} eq "libvirt" and $ident->{'type'} =~ /^disk/ and $val eq "LIBVIRT-DISK"){
-	    $ident->{'type'} =~ s/_ops//;
-            $string .= "-" . $ident->{'type'};
-	}
-	elsif ($ident->{'plugin'} eq "libvirt" and $ident->{'type'} =~ /^if/ and $val eq "LIBVIRT-NET") {
-	    $ident->{'type'} =~ s/_packets//;
-    	    $string .= "-" . $ident->{'type'};
-	}
-	elsif ($ident->{'plugin'} eq "virt" and $ident->{'type'} =~ /^disk/ and $val eq "LIBVIRT-DISK"){
-	    $ident->{'type'} =~ s/_ops//;
-            $string .= "-" . $ident->{'type'};
-	}
-	elsif ($ident->{'plugin'} eq "virt" and $ident->{'type'} =~ /^if/ and $val eq "LIBVIRT-NET") {
-	    $ident->{'type'} =~ s/_packets//;
-    	    $string .= "-" . $ident->{'type'};
-	}
-	else{	
-            $string .= "-" . $ident->{'type'};
-	}
-
-        if (defined $ident->{'type_instance'}) {
-                $string .= "-" . $ident->{'type_instance'};
-        }
-
-	$stringjson = "{#NAME}\":\"" . $string . "\"";
-
-	if( $val eq "ALL"){
-    	    return $stringjson;
-	}
-	elsif( $ident->{'plugin'} eq "libvirt" and $ident->{'type'} eq "virt_cpu_total" and $val eq "LIBVIRT-CPU"){
-    	    return $stringjson;
-	}
-	elsif( $ident->{'plugin'} eq "libvirt" and $ident->{'type'} =~ /^disk$/ and $val eq "LIBVIRT-DISK"){
-    	    return $stringjson;
-	}
-	elsif( $ident->{'plugin'} eq "libvirt" and $ident->{'type'} =~ /^if$/ and $val eq "LIBVIRT-NET"){
-    	    return $stringjson;
-	}
-	elsif( $ident->{'plugin'} eq "virt" and $ident->{'type'} eq "virt_cpu_total" and $val eq "LIBVIRT-CPU"){
-    	    return $stringjson;
-	}
-	elsif( $ident->{'plugin'} eq "virt" and $ident->{'type'} =~ /^disk$/ and $val eq "LIBVIRT-DISK"){
-    	    return $stringjson;
-	}
-	elsif( $ident->{'plugin'} eq "virt" and $ident->{'type'} =~ /^if$/ and $val eq "LIBVIRT-NET"){
-    	    return $stringjson;
-	}
-	# unknown plugin / known plugin not found
-}
-
-sub listval {
-	my $sock = shift || return;
-	my $line = shift;
-
-	my @res;
-
-	if ($line ne "") {
-		print STDERR "Synopsis: LISTVAL" . $/;
-		return;
-	}
-
-	@res = $sock->listval();
-
-	if (! @res) {
-	    print STDERR "socket error: " . $sock->{'error'} . $/;
-	    return;
-	}
-
-	my $firstline = 1;
-
-	print "{\n\t\"data\":[\n\n";
-
-	foreach my $ident (@res) {
-
-      my $rs = putidjson($ident);
-	   
-	   if(length($rs) > 0){
-
-	   	print "\t,\n" if not $firstline;
-	   	$firstline = 0;
-	   	print "\t{\n";
-
-	   	print "\t\t\"" . putidjson($ident) . "\n";
-
-	   	print "\t}\n";
-	   } #end of if
-
-	} #end of foreach
-
-	print "\n\t]\n";
-	print "}\n";
-
-	return 1;
-}
-
-sub getval {
-        my $sock = shift || return;
-        my $line = shift || return;
-
-        my @line = tokenize($line);
-
-        my $id;
-        my $vals;
-
-	my $err_msg;
-	our $val_type;
-
-        if (! @line) {
-                return;
-        }
-
-        if (scalar(@line) < 1) {
-                print STDERR "Synopsis: GETVAL <id>" . $/;
-                return;
-        }
-
-        $id = getid($line[0]);
-
-        if (! $id) {
-                print STDERR "Invalid id \"$line[0]\"." . $/;
-                return;
-        }
-
-        $vals = $sock->getval(%$id);
-
-        if (! $vals) {
-
-		$err_msg = $sock->{'error'};
-
-		if ("$err_msg" eq "No such value") {
-		    print "0" .$/;
-		    return 1;
-		}
-#		else
-		{
-#            	    print STDERR "socket error: " . $sock->{'error'} . $/;
-            	    print STDERR "socket error: " . $sock->{'error'} . $/;
-		    return;
-                }
-        }
-
-        foreach my $key (keys %$vals) {
-
-	    #debug
-	    #print $line[0] . "\n";
-
-	    if( $line[0] =~ /^.*\/.*virt.*\/virt_cpu_total/ ){
-                print "$vals->{$key}\n";
-	    }
-	    elsif( $line[0] =~ /^.*\/.*virt.*\/disk_ops/ ){
-
-		if($val_type eq "OPS-READ" and $key eq "read"){
-            	    print "$vals->{$key}\n";
-		}
-		elsif($val_type eq "OPS-WRITE" and $key eq "write"){
-            	    print "$vals->{$key}\n";
-		}
-		elsif($val_type eq "OPS"){
-                    print "\t$key: $vals->{$key}\n";
-		}
-	    }
-	    elsif($line[0] =~ /^.*\/.*virt.*\/disk_octets/){
-	    
-		#debug
-		#print "DEBUG: disk_octets options ..." . $/;
-		
-		if($val_type eq "OCT-READ" and $key eq "read"){
-            	    print "$vals->{$key}\n";
-		}
-		elsif($val_type eq "OCT-WRITE" and $key eq "write"){
-            	    print "$vals->{$key}\n";
-		}
-		elsif($val_type eq "OCT"){
-                    print "\t$key: $vals->{$key}\n";
-		}
-
-	    }
-	    elsif($line[0] =~ /^.*\/.*virt.*\/if_packets/){
-
-		#debug
-		#print "DEBUG: if_packets options ..." . $/;
-		
-		if($val_type eq "NET-PACKETS-RX" and $key eq "rx"){
-            	    print "$vals->{$key}\n";
-		}
-		elsif($val_type eq "NET-PACKETS-TX" and $key eq "tx"){
-            	    print "$vals->{$key}\n";
-		}
-		elsif($val_type eq "NET-PACKETS"){
-                    print "\t$key: $vals->{$key}\n";
-		}
-		
-	    }
-	    elsif($line[0] =~ /^.*\/.*virt.*\/if_octets/){
-
-		#debug
-		#print "DEBUG: if_octets options ..." . $/;
-		
-		if($val_type eq "NET-OCTETS-RX" and $key eq "rx"){
-            	    print "$vals->{$key}\n";
-		}
-		elsif($val_type eq "NET-OCTETS-TX" and $key eq "tx"){
-            	    print "$vals->{$key}\n";
-		}
-		elsif($val_type eq "NET-OCTETS"){
-                    print "\t$key: $vals->{$key}\n";
-		}
-		
-	    }
-	    else{
-                print "\t$key: $vals->{$key}\n";
-	    }
-        }
-        return 1;
-}
-
-
diff --git a/scripts/collect-libvirt-handler.pl b/scripts/collect-libvirt-handler.pl
index ce7a3a0..2306919 100755
--- a/scripts/collect-libvirt-handler.pl
+++ b/scripts/collect-libvirt-handler.pl
@@ -11,32 +11,65 @@
 	my @vals;
 	our $val = $ARGV[2] || "undef";
 	our $val_type = $ARGV[3] || "undef";
+        our $collectd_version;
+
+        $collectd_version = `collectd -h |grep \'http://\' | sed \'s/\^.*[^0-9]\\([0-9]*\\.[0-9]*\\.[0-9]*\\).*\$/\\1/\' | tr -d '\n'`;
+
+#        print "INFO: collectd version: " . $collectd_version . "\n";
 
 	if( $command eq "LISTVAL" and $val eq "undef"){
 	    $val = "ALL"
 	}
 
 	if( $command eq "GETVAL"){
-	    
+	
 	    if( $val =~ /^.*-virt_cpu_total/ ){
 		@vals = split(/-virt/, $val);
-		$val = $vals[0] . "/libvirt/" . "virt" . $vals[1]	
+		
+		if( $collectd_version =~ /5.5/ ){
+		   $val = $vals[0] . "/virt-" . $vals[0] . "/virt" . $vals[1]
+		}
+		else{
+		   $val = $vals[0] . "/libvirt/" . "virt" . $vals[1]
+		}
 	    }
 	    elsif($val =~ /^.*-disk-/ and $val_type =~ /^OPS/){
 		@vals = split(/-disk/, $val);
-		    $val = $vals[0] . "/libvirt/disk_ops" .$vals[1]
+		
+		if( $collectd_version =~ /5.5/ ){
+		  $val = $vals[0] . "/virt-" . $vals[0] . "/disk_ops" .$vals[1]
+		}
+		else {
+		  $val = $vals[0] . "/libvirt/disk_ops" .$vals[1]
+		}
 	    }
 	    elsif($val =~ /^.*-disk-/ and $val_type =~ /^OCT/){
 		@vals = split(/-disk/, $val);
+		
+		if( $collectd_version =~ /5.5/ ){
+		    $val = $vals[0] . "/virt-" . $vals[0] . "/disk_octets" .$vals[1]
+		}
+		else {
 		    $val = $vals[0] . "/libvirt/disk_octets" .$vals[1]
+		}
 	    }
 	    elsif($val =~ /^.*-if-/ and $val_type =~ /^NET-PACKETS/){
 		@vals = split(/-if/, $val);
+		if( $collectd_version =~ /5.5/ ){
+		    $val = $vals[0] . "/virt-" . $vals[0] . "/if_packets" . $vals[1]
+		}
+		else {
 		    $val = $vals[0] . "/libvirt/if_packets" . $vals[1]
+		}
 	    }
 	    elsif($val =~ /^.*-if-/ and $val_type =~ /^NET-OCTETS/){
 		@vals = split(/-if/, $val);
+		if( $collectd_version =~ /5.5/ ){
+		    $val = $vals[0] . "/virt-" . $vals[0] . "/if_octets" .$vals[1]
+		}
+		else{
 		    $val = $vals[0] . "/libvirt/if_octets" .$vals[1]
+		}
 	    }
 	    $command .= " " . $val;
 	    
@@ -173,7 +206,17 @@ sub putidjson {
         my $ident = shift || return;
         my $string;
         my $stringjson;
+#        my $stringjson5;
 	our $val;
+#	our $collectd_version;
+
+        #debug dumping
+        sub print_hash {
+            my $href = shift;
+            print "$_\t=> $href->{$_}\n" for keys %{$href};
+        }
+        #print_hash($ident);
+        #end of debug dumping
 
         $string = $ident->{'host'};
 
@@ -181,7 +224,7 @@ sub putidjson {
 	    $string .= "-" . $ident->{'plugin'};
 	}
 
-        if (defined $ident->{'plugin_instance'}) {
+        if (defined $ident->{'plugin_instance'} and $ident->{'plugin'} ne "virt") {
                 $string .= "-" . $ident->{'plugin_instance'};
         }
 
@@ -193,6 +236,14 @@ sub putidjson {
 	    $ident->{'type'} =~ s/_packets//;
     	    $string .= "-" . $ident->{'type'};
 	}
+	elsif ($ident->{'plugin'} eq "virt" and $ident->{'type'} =~ /^disk/ and $val eq "LIBVIRT-DISK"){
+	    $ident->{'type'} =~ s/_ops//;
+            $string .= "-" . $ident->{'type'};
+	}
+	elsif ($ident->{'plugin'} eq "virt" and $ident->{'type'} =~ /^if/ and $val eq "LIBVIRT-NET") {
+	    $ident->{'type'} =~ s/_packets//;
+    	    $string .= "-" . $ident->{'type'};
+	}
 	else{	
             $string .= "-" . $ident->{'type'};
 	}
@@ -215,6 +266,16 @@ sub putidjson {
 	elsif( $ident->{'plugin'} eq "libvirt" and $ident->{'type'} =~ /^if$/ and $val eq "LIBVIRT-NET"){
     	    return $stringjson;
 	}
+	elsif( $ident->{'plugin'} eq "virt" and $ident->{'type'} eq "virt_cpu_total" and $val eq "LIBVIRT-CPU"){
+    	    return $stringjson;
+	}
+	elsif( $ident->{'plugin'} eq "virt" and $ident->{'type'} =~ /^disk$/ and $val eq "LIBVIRT-DISK"){
+    	    return $stringjson;
+	}
+	elsif( $ident->{'plugin'} eq "virt" and $ident->{'type'} =~ /^if$/ and $val eq "LIBVIRT-NET"){
+    	    return $stringjson;
+	}
+	# unknown plugin / known plugin not found
 }
 
 sub listval {
@@ -235,10 +296,6 @@ sub listval {
 	    return;
 	}
 
-#	foreach my $ident (@res) {
-#		print putidB($ident);
-#	}
-
 	my $firstline = 1;
 
 	print "{\n\t\"data\":[\n\n";
@@ -317,11 +374,11 @@ sub getval {
 	    #debug
 	    #print $line[0] . "\n";
 
-	    if( $line[0] =~ /^.*\/libvirt\/virt_cpu_total/ ){
+	    if( $line[0] =~ /^.*\/.*virt.*\/virt_cpu_total/ ){
                 print "$vals->{$key}\n";
 	    }
-	    elsif($line[0] =~ /^.*\/libvirt\/disk_ops/){
-	    
+	    elsif( $line[0] =~ /^.*\/.*virt.*\/disk_ops/ ){
+
 		if($val_type eq "OPS-READ" and $key eq "read"){
             	    print "$vals->{$key}\n";
 		}
@@ -332,7 +389,7 @@ sub getval {
                     print "\t$key: $vals->{$key}\n";
 		}
 	    }
-	    elsif($line[0] =~ /^.*\/libvirt\/disk_octets/){
+	    elsif($line[0] =~ /^.*\/.*virt.*\/disk_octets/){
 	    
 		#debug
 		#print "DEBUG: disk_octets options ..." . $/;
@@ -348,7 +405,7 @@ sub getval {
 		}
 
 	    }
-	    elsif($line[0] =~ /^.*\/libvirt\/if_packets/){
+	    elsif($line[0] =~ /^.*\/.*virt.*\/if_packets/){
 
 		#debug
 		#print "DEBUG: if_packets options ..." . $/;
@@ -364,7 +421,7 @@ sub getval {
 		}
 		
 	    }
-	    elsif($line[0] =~ /^.*\/libvirt\/if_octets/){
+	    elsif($line[0] =~ /^.*\/.*virt.*\/if_octets/){
 
 		#debug
 		#print "DEBUG: if_octets options ..." . $/;
@@ -387,3 +444,4 @@ sub getval {
         return 1;
 }
 
+

From 5f1da0d4a9a6d26204e03a09639c9adc2ceddedb Mon Sep 17 00:00:00 2001
From: Patrik Majer <patrik.majer@atlas.cz>
Date: Sat, 27 Feb 2016 09:17:35 +0100
Subject: [PATCH 23/23] update testing

---
 README.md | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/README.md b/README.md
index 5dd3e64..22e419b 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,14 @@
 
 A Zabbix templates for libvirt stats
 
+Version 1.4.0 and higher are tested on:
+
+> CentOS 6.x x86_64, Collectd 4.10
+> Zabbix 2.2, Zabbix 2.4
+
+> CentOS 7.x x86_64, Collectd 5.5
+> Zabbix 2.2, Zabbix 2.4
+
 versions 1.2 and lower were tested on:
 
 > Ubuntu 12.04 x86_64 with KVM (kernel 3.5.0-44), collectd 4.10