error “Can’t locate Switch.pm in @INC (you may need to install the Switch module) ” ketika mengeksekusi script check_apc.pl nagios

Kemarin saya sedang mencoba menambahkan plugin check_apc ke nagios untuk memonitoring UPS APC 2000V yang ada di ruang server, monitoring nya sebenar nya berbasis SNMP Oid dan sudah ada yang membuat script nya di https://exchange.nagios.org/directory/Plugins/Hardware/UPS/APC/Check-APC-UPS/details

namun ketika mencoba mengeksekusi script perl nya terdapat error

[email protected]:~# /usr/local/nagios/libexec/check_apc.pl 
Can't locate Switch.pm in @INC (you may need to install the Switch module) (@INC contains: /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl .) at /usr/local/nagios/libexec/check_apc.pl line 22.
BEGIN failed--compilation aborted at /usr/local/nagios/libexec/check_apc.pl line 22.
[email protected]:~# apt install switch.pm
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package switch.pm
E: Couldn't find any package by regex 'switch.pm'
[email protected]:~#

nah dari error di atas dapat di ketahui di server nagios saya belum ada modul ‘switch.pm’ di perl nya maka kita bisa install modul tersebut lewat CPAN , CPAN singkatan dari (Comprehensive Perl Archive Network) adalah Repositori yang berisi 200.118 Modul dari 36.414 distribusi perangkat lunak yang ditulis dalam bahasa pemrograman Perl yang dikembangkan oleh 13.505 kontributor dari seluruh dunia. Perangkat lunak yang ada di CPAN adalah Perangkat lunak bebas dan kode sumbernya terbuka. berikut langkah nya

[email protected]:~# cpan

CPAN.pm requires configuration, but most of it can be done automatically.
If you answer 'no' below, you will enter an interactive dialog for each
configuration option instead.

Would you like to configure as much as possible automatically? [yes] yes

Autoconfigured everything but 'urllist'.

Now you need to choose your CPAN mirror sites.  You can let me
pick mirrors for you, you can select them from a list or you
can enter them by hand.

Would you like me to automatically choose some CPAN mirror
sites for you? (This means connecting to the Internet) [yes] yes
Trying to fetch a mirror list from the Internet
Fetching with LWP:
http://www.perl.org/CPAN/MIRRORED.BY

Looking for CPAN mirrors near you (please be patient)
...................... done!

New urllist
  http://cpan.mirror.choon.net/
  http://cpan.excellmedia.net/
  http://ftp.kr.freebsd.org/pub/CPAN/

Autoconfiguration complete.

commit: wrote '/root/.cpan/CPAN/MyConfig.pm'

You can re-run configuration any time with 'o conf init' in the CPAN shell
Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v2.00)
Enter 'h' for help.

cpan[1]>

nah ketika muncul shell cpan nya bisa kita install module swicth.pm dengan mengetikan ” install Switch ” dan exit ketika sudah selesai

Fetching with LWP:
http://cpan.mirror.choon.net/authors/01mailrc.txt.gz
Reading '/root/.cpan/sources/authors/01mailrc.txt.gz'
............................................................................DONE
Fetching with LWP:
http://cpan.mirror.choon.net/modules/02packages.details.txt.gz
Reading '/root/.cpan/sources/modules/02packages.details.txt.gz'
  Database was generated on Fri, 20 Nov 2020 00:41:03 GMT
.............
  New CPAN.pm version (v2.28) available.
  [Currently running version is v2.00]
  You might want to try
    install CPAN
    reload cpan
  to both upgrade CPAN.pm and run the new version without leaving
  the current session.


...............................................................DONE
Fetching with LWP:
http://cpan.mirror.choon.net/modules/03modlist.data.gz
Reading '/root/.cpan/sources/modules/03modlist.data.gz'
DONE
Writing /root/.cpan/Metadata
Running install for module 'Switch'
Running make for C/CH/CHORNY/Switch-2.17.tar.gz
Fetching with LWP:
http://cpan.mirror.choon.net/authors/id/C/CH/CHORNY/Switch-2.17.tar.gz
Fetching with LWP:
http://cpan.mirror.choon.net/authors/id/C/CH/CHORNY/CHECKSUMS
Checksum for /root/.cpan/sources/authors/id/C/CH/CHORNY/Switch-2.17.tar.gz ok
Scanning cache /root/.cpan/build for sizes
DONE

  CPAN.pm: Building C/CH/CHORNY/Switch-2.17.tar.gz

Checking if your kit is complete...
Looks good
Writing Makefile for Switch
Writing MYMETA.yml and MYMETA.json
cp Switch.pm blib/lib/Switch.pm
Manifying blib/man3/Switch.3pm
  CHORNY/Switch-2.17.tar.gz
  /usr/bin/make -- OK
'YAML' not installed, will not store persistent state
Running make test
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/given.t ... ok       
t/nested.t .. ok   
t/switch.t .. ok       
All tests successful.
Files=3, Tests=590,  1 wallclock secs ( 0.05 usr  0.03 sys +  0.23 cusr  0.02 csys =  0.33 CPU)
Result: PASS
  CHORNY/Switch-2.17.tar.gz
  /usr/bin/make test -- OK
Running make install
Installing /usr/local/share/perl/5.18.2/Switch.pm
Installing /usr/local/man/man3/Switch.3pm
Appending installation info to /usr/local/lib/perl/5.18.2/perllocal.pod
  CHORNY/Switch-2.17.tar.gz
  /usr/bin/make install  -- OK

cpan[2]> exit
Terminal does not support GetHistory.
Lockfile removed.
[email protected]:~# 

kemudian saya coba eksekusi lagi file check_apc.pl nya dan script nya running.

[email protected]:~# /usr/local/nagios/libexec/check_apc.pl 

/uslocal/nagios/libexec/check_apc.pl - v2.2

Nagios script to check status of an APC Symmetra Uninteruptable Power Supply.

Usage:
-H  Address of hostname of UPS (required)
-C  SNMP community string (required)
-l  Command (optional, see command list)
-p  SNMP port (optional, defaults to port 161)
-t  Connection timeout (optional, default 10s)
-w  Warning threshold (optional, see commands)
-c  Critical threshold (optional, see commands)
-h  Use High Precision values for InputVoltage/OutputVoltage/OutputCurrent
-u  Script / connection errors will return unknown rather than critical

Commands (supplied with -l argument):

    id
        The UPS model name (e.g. 'APC Smart-UPS 600') and interlan info about Firmware, CPU S/N and manufacturing date

    bat_status
        The status of the UPS batteries

    bat_capacity
        The remaining battery capacity expressed in percent of full capacity

    bat_temp
        The current internal UPS temperature expressed in Celsius

    bat_run_remaining
        The UPS battery run time remaining before battery exhaustion
        ** NB: thresholds must be expressed in minutes **

    bat_replace
        Indicates whether the UPS batteries need replacing

    bat_num_batt
        The number of external battery packs connected to the UPS

    bat_num_bad_batt
        The number of external battery packs connected to the UPS that are defective

    bat_act_volt
        The actual battery bus voltage in Volts
        ** NB: thresholds must be expressed in range as nearest values. ex: normal=220, warning=215:225, critical=210:230 **
        ** Additionally, the checks will look for Nominal Voltage (as returned by the UPS), and exit as CRITICAL if Actual Voltage is LOWER or Equal **
        
    power_modules
        The status of the Power Modules

    in_phase
        The current AC input phase

    in_volt
        The current utility line voltage in VAC
        ** NB: thresholds must be expressed in range as nearest values. ex: normal=220, warning=215:225, critical=210:230 **

    in_freq
        The current input frequency to the UPS system in Hz
        ** NB: thresholds must be expressed in range as nearest values. ex: normal=50, warning=45:55, critical=40:60 **

    out_status
        The current state of the UPS

    out_phase
        The current output phase

    out_volt
        The output voltage of the UPS system in VAC
        ** NB: thresholds must be expressed in range as nearest values. ex: normal=220, warning=215:225, critical=210:230 **

    out_freq
        The current output frequency of the UPS system in Hz
        ** NB: thresholds must be expressed in range as nearest values. ex: normal=50, warning=45:55, critical=40:60 **

    out_load
        The current UPS load expressed in percent of rated capacity

    out_current
        The current in amperes drawn by the load on the UPS

    comm_status
        The status of agent's communication with UPS.

No command is supplied, the script return OKAY with the UPS model information.

Example:
/uslocal/nagios/libexec/check_apc.pl -H ups1.domain.local -C public -l bat_status

 --> Not all required options were specified. <--

[email protected]:~#

semoga bermanfaat 🙂

refernsi :

https://id.wikipedia.org/wiki/CPAN

No Comments, Be The First!

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.