# # Copyright (c) 2001-2012 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary AntivirusEngine ComponentState Module ## @author dl-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::Antivirus =head1 DESCRIPTION C is a derived class of L. It represents the state of an ONTAP AntivirusEngine. A related class is L, which represents access to an ONTAP AntivirusEngine. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the Antivirus element are the attributes of the Antivirus ComponentState. =over =item C<< vendor >> The antivirus vendor. Can be any of "none", "sophos" or "mcafee" Filled in for CMode CLI/ZAPI. Maps to: CM ZAPI: vendor =item C<< state >> The state of the antivirus engine (on or off) Applicable for CMode CLI/ZAPI. Maps to: CM ZAPI: is-enabled =item C<< avs_state >> Antivirus Runtime state Filled in for CMode CLI. =item C<< auto_update >> Is Antivirus Auto-update on or off Filled in for CMode CLI. =item C<< num_license >> Number of licenses Filled in for CMode CLI. =item C<< sophos_http_url_intel32 >> The URL from which sophos updates are downloaded from for Intel 32-bit machines (This field appears to only be valid for very early RR builds, and has since been replaced by sophos_http_url) Filled in for CMode CLI. =item C<< sophos_http_url_amd64 >> The URL from which sophos updates are downloaded from for AMD 64-bit machines (This field appears to only be valid for very early RR builds, and has since been replaced by sophos_http_url)) Filled in for CMode CLI. =item C<< sophos_http_url >> The URL from which to download sophos updates. (This could be a URL or could just be "SOPHOS" which will internally get automatically mapped into the appropriate URL) Filled in for CMode CLI. =item C<< sophos_http_user >> The Sophos HTTP Username Filled in for CMode CLI. =item C<< sophos_http_password >> The Sophos HTTP Password Filled in for CMode CLI. =item C<< product_info >> Product Information Filled in for CMode CLI/ZAPI. Maps to: CM ZAPI: prod-info =item C<< mcafee_http_url >> The URL from which to download McAfee updates. Filled in for CMode CLI. =item C<< mcafee_license_key >> McAfee License Key Filled in for CMode CLI. =item C<< mcafee_license_type >> McAfee License Type Filled in for CMode CLI. =item C<< mcafee_license_expiry >> The expiry date of the McAfee license. (In the form MM/DD/YYYY HH:MM::SS) Filled in for CMode CLI. =item C<< mcafee_license_url >> URL from which to get the McAfee license =item C<< mcafee_node_id >> Filled in for CMode CLI. =item C<< mcafee_product_id >> Filled in for CMode CLI. =item C<< mcafee_license_url >> Filled in for CMode CLI. =item C<< trend_activation_code >> Filled in for CMode CLI. =item C<< trend_license_type >> Filled in for CMode CLI. =item C<< trend_http_url >> Filled in for CMode CLI. =item C<< trend_license_expiry >> Filled in for CMode CLI. =back =cut package NACL::CS::AntivirusEngine; use strict; use warnings; use Params::Validate qw(validate); use NACL::ComponentUtils qw(_dump_one); use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use Data::Dumper; use NACL::Exceptions::NoElementsFound qw(:try); use base 'NACL::CS::ComponentState::ONTAP'; use Class::MethodMaker [ scalar => 'vendor', scalar => 'state', scalar => 'avs_state', scalar => 'auto_update', scalar => 'num_license', scalar => 'sophos_http_url_intel32', scalar => 'sophos_http_url_amd64', scalar => 'sophos_http_url', scalar => 'sophos_http_user', scalar => 'sophos_http_password', scalar => 'product_info', scalar => 'mcafee_http_url', scalar => 'mcafee_license_key', scalar => 'mcafee_license_type', scalar => 'mcafee_license_expiry', scalar => 'mcafee_node_id', scalar => 'mcafee_product_id', #zapi scalar => 'license_key', scalar => 'license_type', scalar => 'license_expiry_time', scalar => 'seats', scalar => 'update_url', scalar => 'mcafee_license_url', scalar => 'trend_activation_code', scalar => 'trend_license_type', scalar => 'trend_http_url', scalar => 'trend_license_expiry', ]; =head1 METHODS =head2 fetch my $AntivirusEngine_state = NACL::CS::AntivirusEngine->fetch(command_interface => $ci, ...); my @AntivirusEngine_states = NACL::CS::AntivirusEngine->fetch(command_interface => $ci, ...); (Class method) Discovers which elements are present and returns their state in ComponentState objects. Called in scalar context it returns only one state object, in list context it returns all state objects. See L for a more detailed description along with a complete explanation of the options it accepts. Supports CMode CLI/ZAPI. Invokes "av-get-engine-info" API for CMode ZAPI. =over =item Exceptions =over =item C When there are no elements matching the query specified or elements of that type doesn't exist, then this exception will be thrown. =back =back =cut sub fetch { $Log->enter() if $may_enter; my $pkg = shift; my @state_objs = $pkg->SUPER::fetch( @_, choices => [ { method => '_fetch_cmode_cli', interface => 'CLI', set => 'CMode', }, { method => '_fetch_cmode_zapi', interface => 'ZAPI', set => 'CMode', }, ], exception_text => 'No matching antivirus engine(s) found', is_singleton => 1, show_cmd => 'antivirus engine show', ); $Log->exit() if $may_exit; return wantarray ? @state_objs : $state_objs[0]; } ## end sub fetch sub _fetch_cmode_cli { $Log->enter() if $may_enter; my $pkg = shift; my @state_objs = $pkg->SUPER::_fetch_cmode_cli( @_, api => 'antivirus_engine_show', is_singleton => 1 ); $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_cmode_cli sub _fetch_cmode_zapi { $Log->enter() if $may_enter; my ($pkg, @args) = @_; my %opts = validate @args, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my $caught_exception; my $ci_response; # Displays the antivirus engine and its configuration. try { $ci_response = $apiset->av_get_engine_info(); } catch NACL::APISet::Exceptions::ResponseException with { # A caught exception indicates that the Antivirus Engine being looked for # does not exist. We catch the exception and return immediately. The # 'fetch' frontend decides whether to throw a NoElementsFound # exception based on the value of 'allow_empty' $caught_exception = 1; }; return if ($caught_exception); my $ci_output = $ci_response->get_parsed_output(); my @state_objs; my $conversion_values = {'true' => 'on', 'false' => 'off'}; foreach my $row (@{$ci_output}) { my $state_fields = $pkg->_zapi_hash_copy( source => $row, source_has_extra_arrays => 1, copy => [ qw(seats vendor license-key license-type update-url license-expiry-time) ], map => [ "prod-info" => "product-info", "is-enabled" => "state", ], ); my $obj = $pkg->new(); $obj->_set_fields(row => $state_fields); foreach my $key (%$obj) { if (ref($obj->{$key}) eq "HASH" && keys(%{$obj->{$key}}) == 0) { $obj->{$key} = '""'; } } ## end foreach my $key (%$obj) if (defined $obj->state()) { $obj->state($conversion_values->{$obj->state()}); } push @state_objs, $obj; } ## end foreach my $row ( @{$ci_output... $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_cmode_zapi 1;