OSLV-Monitor

 view release on metacpan or  search on metacpan

lib/OSLV/Monitor/Backends/FreeBSD.pm  view on Meta::CPAN

	if ($@) {
		push( @{ $data->{errors} }, 'decoding output from "jls -h --libxo json 2> /dev/null" failed... ' . $@ );
		return $data;
	}
	if (   defined($jls)
		&& ref($jls) eq 'HASH'
		&& defined( $jls->{'jail-information'} )
		&& ref( $jls->{'jail-information'} ) eq 'HASH'
		&& defined( $jls->{'jail-information'}{jail} )
		&& ref( $jls->{'jail-information'}{jail} ) eq 'ARRAY' )
	{
		foreach my $jls_jail ( @{ $jls->{'jail-information'}{jail} } ) {
			if ( defined( $jls_jail->{name} ) && defined( $jls_jail->{jid} ) ) {
				if ( $ENV{'OSLV_MONITOR_DEBUG'} ) {
					warn(     'DEBUG, '
							. join( '.', gettimeofday )
							. ': backend run processing jname="'
							. $jls_jail->{name}
							. '" jid="'
							. $jls_jail->{jid}
							. '"' );
				}

				my $jname        = $jls_jail->{name};
				my $include_jail = $self->{'obj'}->include($jname);

				if ($include_jail) {
					if ( $ENV{'OSLV_MONITOR_DEBUG'} ) {
						warn( 'DEBUG, ' . join( '.', gettimeofday ) . ': backend run calling clone($base_stats)' );
					}

					$data->{oslvms}{$jname} = clone($base_stats);

					if ( $ENV{'OSLV_MONITOR_DEBUG'} ) {
						warn( 'DEBUG, ' . join( '.', gettimeofday ) . ': backend run done clone($base_stats) done' );
					}

					# finds each ip ifconfig shows in a jail
					if ( $ENV{'OSLV_MONITOR_DEBUG'} ) {
						warn(     'DEBUG, '
								. join( '.', gettimeofday )
								. ': backend run calling "ifconfig -j '
								. $jname
								. ' 2> /dev/null"' );
					}
					my $output = `ifconfig -j $jname 2> /dev/null`;
					my %found_IPv4;
					my %found_IPv6;
					if ( $? eq 0 ) {
						if ( $ENV{'OSLV_MONITOR_DEBUG'} ) {
							warn(     'DEBUG, '
									. join( '.', gettimeofday )
									. ': backend run processing ifconfig info for jail' );
						}
						my @output_split = split( /\n/, $output );
						my $interface;
						foreach my $line (@output_split) {
							if ( $line =~ /^[a-zA-Z].*\:[\ \t]+flags\=/ ) {
								$interface = $line;
								$interface =~ s/\:[\ \t]+flags.*//;
							} elsif ( $line =~ /^[\ \t]+inet6 /
								&& defined($interface) )
							{
								$line =~ s/^[\ \t]+inet6 //;
								$line =~ s/\ .*$//;
								$line =~ s/\%.*$//;
								$found_IPv6{$line} = $interface;
							} elsif ( $line =~ /^[\ \t]+inet /
								&& defined($interface) )
							{
								$line =~ s/^[\ \t]+inet //;
								$line =~ s/ .*$//;
								$found_IPv4{$line} = $interface;
							}
						} ## end foreach my $line (@output_split)
					} elsif ( $ENV{'OSLV_MONITOR_DEBUG'} ) {
						warn( 'DEBUG, ' . join( '.', gettimeofday ) . ': backend run ifconfig exited non-zero' );
					}
					## end if ( $? eq 0 )

					foreach my $ip_key (@IP_keys) {
						my @current_IPs;

						if ( $ip_key eq 'ip4.addr' ) {
							@current_IPs = keys(%found_IPv4);
						} else {
							@current_IPs = keys(%found_IPv6);
						}

						if (   defined( $jls_jail->{$ip_key} )
							&& ref( $jls_jail->{$ip_key} ) eq 'ARRAY'
							&& defined( $jls_jail->{$ip_key}[0] ) )
						{
							foreach my $ip ( @{ $jls_jail->{$ip_key} } ) {
								if ( ref($ip) eq '' && !defined( $found_IPv4{$ip} ) && !defined( $found_IPv6{$ip} ) ) {
									if (   $ip =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/
										|| $ip =~ /^[\:0-9a-fA-F]+$/ )
									{
										push( @current_IPs, $ip );
									}
								}
							}
						} ## end if ( defined( $jls_jail->{$ip_key} ) && ref...)
						foreach my $ip (@current_IPs) {
							my $ip_if;
							my $ip_gw;
							my $ip_gw_if;

							if ( $ip_key eq 'ip4.addr'
								&& defined( $found_IPv4{$ip} ) )
							{
								$ip_if = $found_IPv4{$ip};
							} elsif ( $ip_key eq 'ip6.addr'
								&& defined( $found_IPv6{$ip} ) )
							{
								$ip_if = $found_IPv6{$ip};
							}
							# set the ip type flag for netstat
							my $ip_flag = '-6';
							if ( $ip_key eq 'ip4.addr' ) {
								$ip_flag = '-4';
							}

							# fetch route info for the jail



( run in 0.844 second using v1.01-cache-2.11-cpan-5837b0d9d2c )