Ad Widget

Collapse

Monitoramento de VPN Sonicwall

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ronaldo
    Junior Member
    • Dec 2021
    • 1

    #16
    Bom dia, quando tento testar apresenta este erro, alguém poderia ajudar ?

    check_vpn.pl: line 20: use: comando não encontrado
    check_vpn.pl: line 20: $'\r': comando não encontrado
    check_vpn.pl: line 21: $'\r': comando não encontrado
    check_vpn.pl: line 22: erro de sintaxe próximo do `token' não esperado `('
    'heck_vpn.pl: line 22: `use Getopt::Long qw(:config no_ignore_case);

    Comment

    • Laffitte Rodrigues
      Junior Member
      • Dec 2022
      • 1

      #17
      Boa tarde, pessoal.
      Também to com pro no timeout.
      Eu tentei achar nos script mas n achei, o timeout seria no zabbix_conf?

      Comment

      • felipesorz
        Junior Member
        • Jul 2023
        • 24

        #18
        Boa tarde,
        Alguem poderia ajudar como fazer no sonicwall TZ570 e tendo o zabbix no Ubuntu ?

        "
        1 - Instale os pacotes:
        #yum install epel-release net-snmp-perl

        2 - Carregue o módulo abaixo:

        #perl -MCPAN -e 'install Net::SNMP'
        "

        Os passos 1 e 2 em especifico pois no ubuntu não foi, mas ja tenho o snmpd instalado.
        Abs,

        Comment

        • lukaslhs
          Junior Member
          • Dec 2024
          • 1

          #19
          Fala pessoal tudo bem?

          Tive a necessidade recente de também monitorar as VPNs no Sonicwall e tomei a liberdade de "melhorar" o script disponibilizado.

          O script atualizado deve ser colocado em /usr/lib/zabbix/externalscripts e configurado a execução do mesmo (chmod +x check_vpn.pl). A usagem dele para fins de teste são:
          • TRAZER TODAS AS VPNS ATIVAS E UP (OBRIGATORIAMENTE ESSE SCRIPT TRÁS O STATUS COMO UP) e ele é usado na descoberta do template:
          ./check_vpn.pl.bk -H <hostip> -C <communitysnmp> -V LIST_ALL_VPNS
          • TRAZER STATUS DE VPN ESPECÍFICA (SERÁ USADO NOS ITENS).
          ./check_vpn.pl.bk -H <hostip> -C <communitysnmp> -V <nomevpn>

          A lógica é a seguinte: Se ele encontrar a vpn o status obviamente é "UP", caso não encontrar, o status é "Down". Eu faço um pré-processamento no zabbix para transformar esses valores em 1 = UP e 0 = DOWN.

          A saída é toda em JSON e de fácil manipulação no template. Essa solução me atendeu e creio que irá suprir a necessidade da comunidade.

          Obrigado.

          Script (salve como quiser, importe no seu servidor ou proxy e configure a execução dele):

          #!/usr/bin/perl -w
          use strict;
          use Getopt::Long qw(:config no_ignore_case);
          use Net::SNMP;
          use JSON;
          use Time::HiRes qw(sleep);

          my ($session, $error, %datatable, $oid, $key, $host, $community, $vpn, $HELP, $result);
          my $vpn_found = 0; # Flag para controle do status do VPN

          my $usage = <<EOF;
          This plug tests to see if a given SonicWALL VPN is active or not.

          Usage: check_vpn -H|host -C|community -V|vpn
          -H, --host=SonicWALL
          IP address of the SonicWALL creating the VPN
          -c, --community
          SNMP community name used to list the active VPN's
          -V,--vpn
          The name of the VPN to check for, or 'LIST_ALL_VPNS' to list all VPNs
          EOF

          my %STATUSCODE = ( 'OK' => '0',
          'WARNING' => '1',
          'CRITICAL' => '2',
          'UNKNOWN' => '3');

          $result = GetOptions("H|host=s" => \$host,
          "C|community=s" => \$community,
          "V|vpn=s" => \$vpn,
          "h|help" => \$HELP,
          );

          # Verifica se os parâmetros são válidos
          if ($HELP) {
          print $usage;
          exit($STATUSCODE{'UNKNOWN'});
          }

          if (!($host && $community)) {
          print "ERROR: Missing SNMP community string.\n";
          print $usage;
          exit($STATUSCODE{'UNKNOWN'});
          }

          if (!($host && $vpn)) {
          print "ERROR: Missing VPN name.\n";
          print $usage;
          exit($STATUSCODE{'UNKNOWN'});
          }

          # Criar a sessão SNMP
          ($session, $error) = Net::SNMP->session(-hostname=>$host,-community=>$community,-port=>161);
          die "session error: $error" unless ($session);

          # Definir OIDs para pegar as informações
          my $sonicSAStatPeerGateway = ".1.3.6.1.4.1.8741.1.3.2.1.1.1.2";
          my $sonicSAStatUserName = ".1.3.6.1.4.1.8741.1.3.2.1.1.1.14";

          # Tentando pegar a tabela de OIDs ativos
          $result = $session->get_table(-baseoid => $sonicSAStatPeerGateway);
          die "request error: ".$session->error unless (defined $result);

          # Pegando os OIDs e armazenando
          my @indexoids = $session->var_bind_names;

          # Loop através dos OIDs e pegar dados de cada um
          foreach my $oid (@indexoids) {
          my @splits = split($sonicSAStatPeerGateway, $oid);
          my $dataindex = $splits[1];
          my $getdata = $session->get_request($oid);
          $datatable{$dataindex} = $getdata->{$oid};
          }

          # Preparando os resultados em formato JSON
          my @services;

          # Verificar o status das VPNs
          foreach my $key (sort keys (%datatable)) {
          my $namedata = $session->get_request($sonicSAStatUserName . $key);
          my $name = $namedata->{$sonicSAStatUserName . $key};

          # Se for para listar todas as VPNs
          if ($vpn eq "LIST_ALL_VPNS") {
          push @services, { VPN => $name, STATUS => "UP" };
          } elsif ($name eq $vpn) { # Se o nome da VPN for igual ao informado
          $vpn_found = 1;
          push @services, { VPN => $name, STATUS => "UP" };
          }
          }

          # Se a VPN específica não for encontrada, marcar como "DOWN"
          if ($vpn ne "LIST_ALL_VPNS" && !$vpn_found) {
          push @services, { VPN => $vpn, STATUS => "DOWN" };
          }

          # Transformar os dados em formato JSON e exibir
          my $json = encode_json({ data => \@services });
          print "$json\n";

          # Fechar a sessão SNMP
          $session->close;

          # Finalizando o script com erro se necessário
          exit($vpn_found ? $STATUSCODE{'OK'} : $STATUSCODE{'CRITICAL'});



          Template (salve o conteúdo como .yaml e importe no zabbix):

          zabbix_export:
          version: '6.4'
          template_groups:
          - uuid: a571c0d144b14fd4a87a9d9b2aa9fcd6
          name: Templates/Applications
          templates:
          - uuid: 9c0eccae03404cc6ad024752d8eb9503
          template: 'SonicWall by API - VPN'
          name: 'SonicWall by API - VPN'
          groups:
          - name: Templates/Applications
          discovery_rules:
          - uuid: 5ecd35c69b324662976645d9dd5f8adc
          name: 'Descoberta VPN'
          type: EXTERNAL
          key: 'check_vpn.pl["-H","{HOST.CONN}","-C","{$SNMP_COMMUNITY}","-V","LIST_ALL_VPNS"]'
          delay: 10m
          lifetime: 1d
          item_prototypes:
          - uuid: ec12cec7d86044739dfec18961ca2296
          name: 'VPN {#VPN} - Status'
          type: EXTERNAL
          key: 'check_vpn.pl["-H","{HOST.CONN}","-C","{$SNMP_COMMUNITY}","-V","{#VPN}"]'
          history: 7d
          trends: 90d
          preprocessing:
          - type: JSONPATH
          parameters:
          - '$.data[0].STATUS'
          - type: STR_REPLACE
          parameters:
          - UP
          - '1'
          - type: STR_REPLACE
          parameters:
          - DOWN
          - '0'
          tags:
          - tag: Componente
          value: VPN
          trigger_prototypes:
          - uuid: e2cfad641b3846b1948c6c1191c143fd
          expression: 'last(/SonicWall by API - VPN/check_vpn.pl["-H","{HOST.CONN}","-C","{$SNMP_COMMUNITY}","-V","{#VPN}"])=0'
          name: 'VPN {#VPN} - Status Down'
          priority: AVERAGE
          description: 'VPN {#VPN} está com Status Down - Verificar'
          tags:
          - tag: Componente
          value: VPN
          lld_macro_paths:
          - lld_macro: '{#STATUS}'
          path: $.STATUS
          - lld_macro: '{#VPN}'
          path: $.VPN
          preprocessing:
          - type: JSONPATH
          parameters:
          - '$.data[*]'
          tags:
          - tag: Componente
          value: VPN
          macros:
          - macro: '{$PASSWORD}'
          - macro: '{$URL}'
          - macro: '{$USER}'

          Comment

          • felipesorz
            Junior Member
            • Jul 2023
            • 24

            #20
            Originally posted by lukaslhs
            Fala pessoal tudo bem?

            Tive a necessidade recente de também monitorar as VPNs no Sonicwall e tomei a liberdade de "melhorar" o script disponibilizado.

            O script atualizado deve ser colocado em /usr/lib/zabbix/externalscripts e configurado a execução do mesmo (chmod +x check_vpn.pl). A usagem dele para fins de teste são:
            • TRAZER TODAS AS VPNS ATIVAS E UP (OBRIGATORIAMENTE ESSE SCRIPT TRÁS O STATUS COMO UP) e ele é usado na descoberta do template:
            ./check_vpn.pl.bk -H <hostip> -C <communitysnmp> -V LIST_ALL_VPNS
            • TRAZER STATUS DE VPN ESPECÍFICA (SERÁ USADO NOS ITENS).
            ./check_vpn.pl.bk -H <hostip> -C <communitysnmp> -V <nomevpn>

            A lógica é a seguinte: Se ele encontrar a vpn o status obviamente é "UP", caso não encontrar, o status é "Down". Eu faço um pré-processamento no zabbix para transformar esses valores em 1 = UP e 0 = DOWN.

            A saída é toda em JSON e de fácil manipulação no template. Essa solução me atendeu e creio que irá suprir a necessidade da comunidade.

            Obrigado.

            Script (salve como quiser, importe no seu servidor ou proxy e configure a execução dele):

            #!/usr/bin/perl -w
            use strict;
            use Getopt::Long qw(:config no_ignore_case);
            use Net::SNMP;
            use JSON;
            use Time::HiRes qw(sleep);

            my ($session, $error, %datatable, $oid, $key, $host, $community, $vpn, $HELP, $result);
            my $vpn_found = 0; # Flag para controle do status do VPN

            my $usage = <<EOF;
            This plug tests to see if a given SonicWALL VPN is active or not.

            Usage: check_vpn -H|host -C|community -V|vpn
            -H, --host=SonicWALL
            IP address of the SonicWALL creating the VPN
            -c, --community
            SNMP community name used to list the active VPN's
            -V,--vpn
            The name of the VPN to check for, or 'LIST_ALL_VPNS' to list all VPNs
            EOF

            my %STATUSCODE = ( 'OK' => '0',
            'WARNING' => '1',
            'CRITICAL' => '2',
            'UNKNOWN' => '3');

            $result = GetOptions("H|host=s" => \$host,
            "C|community=s" => \$community,
            "V|vpn=s" => \$vpn,
            "h|help" => \$HELP,
            );

            # Verifica se os parâmetros são válidos
            if ($HELP) {
            print $usage;
            exit($STATUSCODE{'UNKNOWN'});
            }

            if (!($host && $community)) {
            print "ERROR: Missing SNMP community string.\n";
            print $usage;
            exit($STATUSCODE{'UNKNOWN'});
            }

            if (!($host && $vpn)) {
            print "ERROR: Missing VPN name.\n";
            print $usage;
            exit($STATUSCODE{'UNKNOWN'});
            }

            # Criar a sessão SNMP
            ($session, $error) = Net::SNMP->session(-hostname=>$host,-community=>$community,-port=>161);
            die "session error: $error" unless ($session);

            # Definir OIDs para pegar as informações
            my $sonicSAStatPeerGateway = ".1.3.6.1.4.1.8741.1.3.2.1.1.1.2";
            my $sonicSAStatUserName = ".1.3.6.1.4.1.8741.1.3.2.1.1.1.14";

            # Tentando pegar a tabela de OIDs ativos
            $result = $session->get_table(-baseoid => $sonicSAStatPeerGateway);
            die "request error: ".$session->error unless (defined $result);

            # Pegando os OIDs e armazenando
            my @indexoids = $session->var_bind_names;

            # Loop através dos OIDs e pegar dados de cada um
            foreach my $oid (@indexoids) {
            my @splits = split($sonicSAStatPeerGateway, $oid);
            my $dataindex = $splits[1];
            my $getdata = $session->get_request($oid);
            $datatable{$dataindex} = $getdata->{$oid};
            }

            # Preparando os resultados em formato JSON
            my @services;

            # Verificar o status das VPNs
            foreach my $key (sort keys (%datatable)) {
            my $namedata = $session->get_request($sonicSAStatUserName . $key);
            my $name = $namedata->{$sonicSAStatUserName . $key};

            # Se for para listar todas as VPNs
            if ($vpn eq "LIST_ALL_VPNS") {
            push @services, { VPN => $name, STATUS => "UP" };
            } elsif ($name eq $vpn) { # Se o nome da VPN for igual ao informado
            $vpn_found = 1;
            push @services, { VPN => $name, STATUS => "UP" };
            }
            }

            # Se a VPN específica não for encontrada, marcar como "DOWN"
            if ($vpn ne "LIST_ALL_VPNS" && !$vpn_found) {
            push @services, { VPN => $vpn, STATUS => "DOWN" };
            }

            # Transformar os dados em formato JSON e exibir
            my $json = encode_json({ data => \@services });
            print "$json\n";

            # Fechar a sessão SNMP
            $session->close;

            # Finalizando o script com erro se necessário
            exit($vpn_found ? $STATUSCODE{'OK'} : $STATUSCODE{'CRITICAL'});



            Template (salve o conteúdo como .yaml e importe no zabbix):

            zabbix_export:
            version: '6.4'
            template_groups:
            - uuid: a571c0d144b14fd4a87a9d9b2aa9fcd6
            name: Templates/Applications
            templates:
            - uuid: 9c0eccae03404cc6ad024752d8eb9503
            template: 'SonicWall by API - VPN'
            name: 'SonicWall by API - VPN'
            groups:
            - name: Templates/Applications
            discovery_rules:
            - uuid: 5ecd35c69b324662976645d9dd5f8adc
            name: 'Descoberta VPN'
            type: EXTERNAL
            key: 'check_vpn.pl["-H","{HOST.CONN}","-C","{$SNMP_COMMUNITY}","-V","LIST_ALL_VPNS"]'
            delay: 10m
            lifetime: 1d
            item_prototypes:
            - uuid: ec12cec7d86044739dfec18961ca2296
            name: 'VPN {#VPN} - Status'
            type: EXTERNAL
            key: 'check_vpn.pl["-H","{HOST.CONN}","-C","{$SNMP_COMMUNITY}","-V","{#VPN}"]'
            history: 7d
            trends: 90d
            preprocessing:
            - type: JSONPATH
            parameters:
            - '$.data[0].STATUS'
            - type: STR_REPLACE
            parameters:
            - UP
            - '1'
            - type: STR_REPLACE
            parameters:
            - DOWN
            - '0'
            tags:
            - tag: Componente
            value: VPN
            trigger_prototypes:
            - uuid: e2cfad641b3846b1948c6c1191c143fd
            expression: 'last(/SonicWall by API - VPN/check_vpn.pl["-H","{HOST.CONN}","-C","{$SNMP_COMMUNITY}","-V","{#VPN}"])=0'
            name: 'VPN {#VPN} - Status Down'
            priority: AVERAGE
            description: 'VPN {#VPN} está com Status Down - Verificar'
            tags:
            - tag: Componente
            value: VPN
            lld_macro_paths:
            - lld_macro: '{#STATUS}'
            path: $.STATUS
            - lld_macro: '{#VPN}'
            path: $.VPN
            preprocessing:
            - type: JSONPATH
            parameters:
            - '$.data[*]'
            tags:
            - tag: Componente
            value: VPN
            macros:
            - macro: '{$PASSWORD}'
            - macro: '{$URL}'
            - macro: '{$USER}'
            Opa, boa tarde.

            Estou com este erro ao tentar importar o template

            Click image for larger version

Name:	image.png
Views:	154
Size:	24.3 KB
ID:	498496

            Comment

            Working...