| 
									
										
										
										
											2015-08-28 10:49:19 +02:00
										 |  |  | #!/usr/bin/perl -w | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-28 10:52:04 +02:00
										 |  |  | # Copyright (C) 2015 Mark Schouten <mark@tuxis.nl> | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  | # modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  | # as published by the Free Software Foundation; version 2 dated June, | 
					
						
							|  |  |  | # 1991. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | # GNU General Public License for more details. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # See http://www.gnu.org/licenses/gpl.txt for the full license | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-28 10:49:19 +02:00
										 |  |  | use constant { | 
					
						
							|  |  |  |     TIMEZONE => 'Europe/Amsterdam' | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use strict; | 
					
						
							|  |  |  | use PVE::API2Client; | 
					
						
							|  |  |  | use PVE::AccessControl; | 
					
						
							|  |  |  | use PVE::INotify; | 
					
						
							|  |  |  | use Data::Dumper; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | my $hostname = PVE::INotify::read_file("hostname"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | my $ticket = PVE::AccessControl::assemble_ticket('root@pam'); | 
					
						
							|  |  |  | my $csrftoken = PVE::AccessControl::assemble_csrf_prevention_token('root@pam'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | my $conn = PVE::API2Client->new( | 
					
						
							|  |  |  |     ticket => $ticket, | 
					
						
							|  |  |  |     csrftoken => $csrftoken, | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-04 14:40:19 +01:00
										 |  |  | my $clustername; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-04 14:30:21 +01:00
										 |  |  | foreach my $child (@{$conn->get("/api2/json/cluster/status")->{'data'}}) { | 
					
						
							|  |  |  |     if ($child->{'type'} eq "cluster") { | 
					
						
							|  |  |  |         $clustername = $child->{'name'}; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-08-28 10:49:19 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-04 14:30:21 +01:00
										 |  |  | if (!defined($clustername)) { | 
					
						
							|  |  |  |         $clustername = $hostname; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-08-28 10:49:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | print "<<<app-proxmox>>>\n"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | print "$clustername\n"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | foreach my $vm (@{$conn->get("/api2/json/nodes/$hostname/netstat")->{'data'}}) { | 
					
						
							|  |  |  | 	my $vmid = $vm->{'vmid'}; | 
					
						
							| 
									
										
										
										
											2016-07-11 17:06:14 +02:00
										 |  |  |     eval { | 
					
						
							|  |  |  |         my $vmname = $conn->get("/api2/json/nodes/$hostname/qemu/$vmid/config")->{'data'}->{'name'}; | 
					
						
							| 
									
										
										
										
											2016-07-13 15:06:57 +02:00
										 |  |  |         my $tmpl = $conn->get("/api2/json/nodes/$hostname/qemu/$vmid/config")->{'data'}->{'template'}; | 
					
						
							|  |  |  |         if (defined($tmpl) && $tmpl == 1) { | 
					
						
							|  |  |  |             die; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-07-11 17:06:14 +02:00
										 |  |  |         print "$vmid/$vm->{'dev'}/$vm->{'in'}/$vm->{'out'}/$vmname\n"; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     eval { | 
					
						
							| 
									
										
										
										
											2016-07-13 15:06:57 +02:00
										 |  |  |         my $vmname = $conn->get("/api2/json/nodes/$hostname/lxc/$vmid/config")->{'data'}->{'hostname'}; | 
					
						
							|  |  |  |         my $tmpl = $conn->get("/api2/json/nodes/$hostname/lxc/$vmid/config")->{'data'}->{'template'}; | 
					
						
							|  |  |  |         if (defined($tmpl) && $tmpl == 1) { | 
					
						
							|  |  |  |             die; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-07-11 17:06:14 +02:00
										 |  |  |         print "$vmid/$vm->{'dev'}/$vm->{'in'}/$vm->{'out'}/$vmname\n"; | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2015-08-28 10:49:19 +02:00
										 |  |  | }; |