Wednesday, September 28, 2022

run Selenium Python Script with Headless Chrome

Installing Selenium and Webdriver for Python

We will use a virtual environment for running Python scripts. Follow the below steps to create Python virtual environment and install the required python modules.

  1. Create a directory to store Python scripts. Then switch to the newly-created directory.
    mkdir tests && cd tests 
    
  2. Set up the Python virtual environment and activate it.
    python3 -m venv venv 
    source venv/bin/activate 
    

 

Once the environment is activated, You will find the updated prompt as shown below screenshot:

Create Python Environment for Selenium on Ubuntu
Create Python Environment for Selenium on Ubuntu
Now use PIP to install the selenium and webdriver-manager Python modules under the virtual environment.
pip install selenium webdriver-manager  
 Installing Selenium and Webdriver Python Module on Ubuntu & DebianInstalling Seleniu

 

 

Selenium Python Script with Headless Chrome

 

 Now, create a sample selenium script in Python that fetches the title of a website.

This script will run headless, So you can run it without an X desktop environment. You can simply SSH to your system and run the below example. Make sure Chromedriver is install in arm64 type. See my other blog

  1. Create a Python script and edit it in your favorite text editor:
    nano test.py 
    
  2. Copy-paste the following Selenium Python script to the file.

    ====

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.chrome.service import Service
    #from webdriver_manager.chrome import ChromeDriverManager
     
    chrome_driver_path="/usr/bin/chromedriver"
    options = Options()
    options.add_argument('--headless')
    options.add_argument('--no-sandbox')
    options.add_argument('--disable-dev-shm-usage')
    #driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
     
    driver= webdriver.Chrome(executable_path=chrome_driver_path, options=options)
    driver.get("https://python.org")
    print(driver.title)
    driver.close()

     ====

     

    Press CTRL + O to save content to file and press CTRL + X to close editor.

  3. Now, run this Python script in a shell.
    python test.py 
    

    You will see the output something like below:

    Running Selenium Python Script in Ubuntu & Debian
    Running the Selenium Python Script

How to install Chromedriver in Arm64 ubuntu linux?

# sudo apt update

# sudo apt-get install chromium-chromedriver

Wednesday, April 13, 2022

lots of Apparmor messages showing DENIED

Problem: 

Sometimes in the /var/log/kern.log, you will get lots of Apparmor messages showing DENIED of certain profile.

Example:

Apr 13 15:52:46 user-x8sti kernel: [15722.914324] audit: type=1400 audit(1649836366.541:15993): apparmor="DENIED" operation="open" profile="snap.net-snmp.snmpd" name="/proc/sys/net/ipv6/conf/lo/forwarding" pid=895 comm="snmpd" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Apr 13 15:52:46 user-x8sti kernel: [15722.914336] audit: type=1400 audit(1649836366.541:15994): apparmor="DENIED" operation="open" profile="snap.net-snmp.snmpd" name="/proc/sys/net/ipv6/neigh/lo/base_reachable_time_ms" pid=895 comm="snmpd" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

 Solution.

Look for the location of the profile then run the apparmor_parser -R command to suppress those messages. -R means to remove the profile.

 Example:

 apparmor_parser -R /var/lib/snapd/apparmor/profiles/snap.net-snmp.snmpd

Friday, March 25, 2022

Bad operator (INTEGER): At line 73 in /usr/share/snmp/mibs/ietf/SNMPv2-PDU when using "service snmptrapd status"

 PROBLEM:

when I tried to load one of the SPG8000A mib to ubuntu SNMP, the net-snmp library just will not parse the mib file to the OID.

as I troubleshoot I found out  

root@user-x8sti:~# service snmptrapd restart                                                                                                 

root@user-x8sti:~# service snmptrapd status                                                                                                
● snmptrapd.service - Simple Network Management Protocol (SNMP) Trap Daemon.
     Loaded: loaded (/lib/systemd/system/snmptrapd.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-03-25 21:15:43 +08; 3s ago
   Main PID: 2441 (snmptrapd)
      Tasks: 1 (limit: 14222)
     Memory: 15.0M
     CGroup: /system.slice/snmptrapd.service
             └─2441 /usr/sbin/snmptrapd -LOw -f -p /run/snmptrapd.pid

Mar 25 21:15:43 user-x8sti systemd[1]: Started Simple Network Management Protocol (SNMP) Trap Daemon..
Mar 25 21:15:43 user-x8sti snmptrapd[2441]: Bad operator (INTEGER): At line 73 in /usr/share/snmp/mibs/ietf/SNMPv2-PDU
Mar 25 21:15:43 user-x8sti snmptrapd[2441]: unknown snmp version 193

Solution:

To fix the error: copy or make a new SNMPv2PDU file in the

/usr/share/mibs/ietf/ directory with the below MIB information
or you can run this command in the linux commandline. 
wget http://pastebin.com/raw.php?i=p3QyuXzZ -O /usr/share/mibs/ietf/SNMPv2-PDU

 Remember to run service snmptrapd restart
this should fix the OID to mib information.

 More troubleshooting at this link:

https://docs.linuxconsulting.mn.it/notes/net-snmp-errors




SNMPv2-PDU DEFINITIONS ::= BEGIN

ObjectName ::= OBJECT IDENTIFIER

ObjectSyntax ::= CHOICE {
      simple           SimpleSyntax,
      application-wide ApplicationSyntax }

SimpleSyntax ::= CHOICE {
      integer-value   INTEGER (-2147483648..2147483647),
      string-value    OCTET STRING (SIZE (0..65535)),
      objectID-value  OBJECT IDENTIFIER }

ApplicationSyntax ::= CHOICE {
      ipAddress-value        IpAddress,
      counter-value          Counter32,
      timeticks-value        TimeTicks,
      arbitrary-value        Opaque,
      big-counter-value      Counter64,
      unsigned-integer-value Unsigned32 }

IpAddress ::= [APPLICATION 0] IMPLICIT OCTET STRING (SIZE (4))

Counter32 ::= [APPLICATION 1] IMPLICIT INTEGER (0..4294967295)

Unsigned32 ::= [APPLICATION 2] IMPLICIT INTEGER (0..4294967295)

Gauge32 ::= Unsigned32

TimeTicks ::= [APPLICATION 3] IMPLICIT INTEGER (0..4294967295)

Opaque ::= [APPLICATION 4] IMPLICIT OCTET STRING

Counter64 ::= [APPLICATION 6]
              IMPLICIT INTEGER (0..18446744073709551615)

-- protocol data units

PDUs ::= CHOICE {
     get-request      GetRequest-PDU,
     get-next-request GetNextRequest-PDU,
     get-bulk-request GetBulkRequest-PDU,
     response         Response-PDU,
     set-request      SetRequest-PDU,
     inform-request   InformRequest-PDU,
     snmpV2-trap      SNMPv2-Trap-PDU,
     report           Report-PDU }

-- PDUs

GetRequest-PDU ::= [0] IMPLICIT PDU

GetNextRequest-PDU ::= [1] IMPLICIT PDU

Response-PDU ::= [2] IMPLICIT PDU

SetRequest-PDU ::= [3] IMPLICIT PDU

-- [4] is obsolete

GetBulkRequest-PDU ::= [5] IMPLICIT BulkPDU

InformRequest-PDU ::= [6] IMPLICIT PDU

SNMPv2-Trap-PDU ::= [7] IMPLICIT PDU

--   Usage and precise semantics of Report-PDU are not defined
--   in this document.  Any SNMP administrative framework making
--   use of this PDU must define its usage and semantics.

Report-PDU ::= [8] IMPLICIT PDU

-- max-bindings INTEGER ::= 2147483647

PDU ::= SEQUENCE {
        request-id INTEGER (-214783648..214783647),
        error-status                -- sometimes ignored
            INTEGER {
                noError(0),
                tooBig(1),
                noSuchName(2),      -- for proxy compatibility
                badValue(3),        -- for proxy compatibility
                readOnly(4),        -- for proxy compatibility
                genErr(5),
                noAccess(6),
                wrongType(7),
                wrongLength(8),
                wrongEncoding(9),
                wrongValue(10),
                noCreation(11),
                inconsistentValue(12),
                resourceUnavailable(13),
                commitFailed(14),
                undoFailed(15),
                authorizationError(16),
                notWritable(17),
                inconsistentName(18)
            },
        error-index                 -- sometimes ignored
            INTEGER (0..2147483647),
        variable-bindings           -- values are sometimes ignored
            VarBindList
    }

BulkPDU ::=                         -- must be identical in
    SEQUENCE {                      -- structure to PDU
        request-id      INTEGER (-214783648..214783647),
        non-repeaters   INTEGER (0..2147483647),
        max-repetitions INTEGER (0..2147483647),
        variable-bindings           -- values are ignored
            -- VarBindList
	    SEQUENCE (SIZE (0..2147483647)) OF VarBind
    }

-- variable binding

VarBind ::= SEQUENCE {
        name ObjectName,
        CHOICE {
            value          ObjectSyntax,
            unSpecified    NULL,    -- in retrieval requests

                                    -- exceptions in responses
            noSuchObject   [0] IMPLICIT NULL,
            noSuchInstance [1] IMPLICIT NULL,
            endOfMibView   [2] IMPLICIT NULL
        }
    }

-- variable-binding list

-- VarBindList ::= SEQUENCE (SIZE (0..2147483647)) OF VarBind

END

Thursday, March 24, 2022

zabbix snmp trap-receiver perl script not able to work.

 Problem:


● snmptrapd.service - Simple Network Management Protocol (SNMP) Trap Daemon.
     Loaded: loaded (/lib/systemd/system/snmptrapd.service; disabled; vendor preset: enable>
     Active: active (running) since Thu 2022-03-24 11:21:20 +08; 4s ago
   Main PID: 4772 (snmptrapd)
      Tasks: 1 (limit: 14222)
     Memory: 2.2M
     CGroup: /system.slice/snmptrapd.service
             └─4772 /usr/sbin/snmptrapd -LOw -f -p /run/snmptrapd.pid

Mar 24 11:21:20 user-x8sti systemd[1]: Started Simple Network Management Protocol (SNMP) Tr>
Mar 24 11:21:20 user-x8sti snmptrapd[4772]: Can't locate NetSNMP/TrapReceiver.pm in @INC (y>
Mar 24 11:21:20 user-x8sti snmptrapd[4772]: BEGIN failed--compilation aborted at /usr/share>
Mar 24 11:21:20 user-x8sti snmptrapd[4772]: embedded perl support failed to initialize (per>
Mar 24 11:21:20 user-x8sti snmptrapd[4772]: unknown snmp version 193
 

 

Another way of checking:

# snmptrapd -On
Can't locate NetSNMP/TrapReceiver.pm in @INC (you may need to install the NetSNMP::TrapReceiver module) (@INC contains: /etc/perl /usr/local/lib/arm-linux-gnueabihf/perl/5.24.1 /usr/local/share/perl/5.24.1 /usr/lib/arm-linux-gnueabihf/perl5/5.24 /usr/share/perl5 /usr/lib/arm-linux-gnueabihf/perl/5.24 /usr/share/perl/5.24 /usr/local/lib/site_perl) at /usr/share/snmp/snmp_perl_trapd.pl line 13.
BEGIN failed--compilation aborted at /usr/share/snmp/snmp_perl_trapd.pl line 13.

 

Solution:

apt install libsnmp-perl
# or
apt install snmptt

 

Rebrand Zabbix

There are several ways in which you can customize and rebrand your Zabbix frontend installation:

  • replace the Zabbix logo with a desired one
  • hide links to Zabbix Support and Zabbix Integrations
  • set a custom link to the Help page
  • change copyright in the footer

How to

To begin with, you need to create a PHP file and save it as usr/share/zabbix/local/conf/brand.conf.php. The contents of the file should be the following:

  1. <?php

  2. return [];

This will hide the links to Zabbix Support and Zabbix Integrations.

To use a custom logo, add the following line to the array from the previous listing:

  1. 'BRAND_LOGO' => '{Path to an image on the disk or URL}',

With the redesign of the main menu in Zabbix 5.0, there are two additional images of the Zabbix logo that can be overridden:

  • BRAND_LOGO_SIDEBAR - displayed when the sidebar is expanded
  • BRAND_LOGO_SIDEBAR_COMPACT - displayed when the sidebar is collapsed

To override:

  1. 'BRAND_LOGO_SIDEBAR' => '{Path to an image on the disk or URL}',
  2. 'BRAND_LOGO_SIDEBAR_COMPACT' => '{Path to an image on the disk or URL}',

Any image format supported by modern browsers can be used: JPG, PNG, SVG, BMP, WebP and GIF.

Custom logos will not be scaled, resized or modified in any way, and will be displayed in their original sizes and proportions, but may be cropped to fit in the corresponding place.

To set a custom copyright notice, add BRAND_FOOTER to the array from the first listing. Please be aware that HTML is not supported here. Setting BRAND_FOOTER to an empty string will hide the copyright notes completely (but the footer will stay in place).

  1. 'BRAND_FOOTER' => '{text}',
Custom help location

To replace the default Help link with a link of your choice, add BRAND_HELP_URL to the array from the first listing.

  1. 'BRAND_HELP_URL' => '{URL}',
File example
  1. <?php

  2. return [
  3. 'BRAND_LOGO' => './images/custom_logo.png',
  4. 'BRAND_LOGO_SIDEBAR' => './images/custom_logo_sidebar.png',
  5. 'BRAND_LOGO_SIDEBAR_COMPACT' => './images/custom_logo_sidebar_compact.png',
  6. 'BRAND_FOOTER' => '© Zabbix'.ZABBIX_VERSION,
  7. 'BRAND_HELP_URL' => 'https://www.example.com/help/'
  8. ];

 The size for the different image :

 

 


 Make all the custom images in photo editing software or use photopea online.

Store all the images in the ./assets/img/ folder.

Edit the

/usr/share/zabbix/local/conf/brand.conf.php 
and input all the respective links and text. 

 Use the below commands to change the favicon too

mv /usr/share/zabbix/favicon.ico /usr/share/zabbix/favicon.ico.bak 
mv /tmp/favicon.png /usr/share/zabbix/favicon.ico