Tích hợp cảnh báo qua telegram với PRTG

Bước 1: cần có 1 con bot trên telegram, cách tạo bot các bạn chat với @botfather và làm theo hướng dẫn. Sau khi thực hiện, sẽ có token trả về, sử dụng để authen đối với các request tới bot
token có dạng đại loại như:
481775980:NAGtU-UYFQfYhufthedUAwMB2XWzRc8F6AA
Bước 2: tạo 1 room chat với con bot chúng ta vừa tạo, cứ tạo cuộc trò chuyện mới sau đó add con bot mới vào.
Bước 3: Lấy chat ID của cuộc trò chuyện vừa tạo
sử dụng URL có định dạng:
https://api.telegram.org/bot<token của bot>/getUpdates
VD: https://api.telegram.org/bot481775980:NAGtU-UYFQfYhufthedUAwMB2XWzRc8F6AA/getUpdates
call lên url mới có với header: “Content-Type: application/json”

curl -H "Content-Type: application/json" https://api.telegram.org/bot481775980:NAGtU-UYFQfYhufthedUAwMB2XWzRc8F6AA/getUpdates

chúng ta sẽ nhận được chuỗi json trả về, với chatID tương ứng

{
  "ok": true,
  "result": [
    {
      "update_id": 911858273,
      "message": {
        "message_id": 15396,
        "from": {
          "id": 432109061,
          "is_bot": false,
          "first_name": "some name",
          "last_name": "ハンサム",
          "username": "some username",
          "language_code": "en"
        },
        "chat": {
          "id": -359110891,
          "title": "GmsABD",
          "type": "group",
          "all_members_are_administrators": true
        },
        "date": 1566359213,
        "new_chat_participant": {
          "id": 471543210,
          "is_bot": true,
          "first_name": "SexyBot",
          "username": "damducbot"
        },
        "new_chat_member": {
          "id": 471543210,
          "is_bot": true,
          "first_name": "SexyBot",
          "username": "damducbot"
        },
        "new_chat_members": [
          {
            "id": 471543210,
            "is_bot": true,
            "first_name": "SexyBot",
            "username": "damducbot"
          }
        ]
      }
    },
    {
      "update_id": 911858274,
      "message": {
        "message_id": 15397,
        "from": {
          "id": 432109061,
          "is_bot": false,
          "first_name": "some name",
          "last_name": "ハンサム",
          "username": "some username",
          "language_code": "en"
        },
        "chat": {
          "id": -359110891,
          "title": "GmsABD",
          "type": "group",
          "all_members_are_administrators": true
        },
        "date": 1566359341,
        "new_chat_photo": [
          {
            "file_id": "AgADBQADsqcxG5SuihmFyQGf595pCVSo-TIABAEAAwIAA2EAAz3VAQABFgQ",
            "file_size": 5297,
            "width": 160,
            "height": 160
          },
          {
            "file_id": "AgADBQADsqcxG5SuihmFyQGf595pCVSo-TIABAEAAwIAA2IAAz7VAQABFgQ",
            "file_size": 11196,
            "width": 320,
            "height": 320
          },
          {
            "file_id": "AgADBQADsqcxG5SuihmFyQGf595pCVSo-TIABAEAAwIAA2MAAz_VAQABFgQ",
            "file_size": 25020,
            "width": 640,
            "height": 640
          }
        ]
      }
    },
    {
      "update_id": 911858275,
      "message": {
        "message_id": 15398,
        "from": {
          "id": 442710299,
          "is_bot": false,
          "first_name": "Mr Dam",
          "username": "Damnnvn"
        },
        "chat": {
          "id": -359110891,
          "title": "GmsABD",
          "type": "group",
          "all_members_are_administrators": true
        },
        "date": 1566359505,
        "new_chat_participant": {
          "id": 867065125,
          "is_bot": false,
          "first_name": "Mr du",
          "username": "mrdu"
        },
        "new_chat_member": {
          "id": 867065125,
          "is_bot": false,
          "first_name": "Mr du",
          "username": "mrdu"
        },
        "new_chat_members": [
          {
            "id": 867065125,
            "is_bot": false,
            "first_name": "Mr du",
            "username": "mrdu"
          }
        ]
      }
    }
  ]
}

Theo như ở trên, chúng ta có nhóm

"chat": {
          "id": -359110891,
          "title": "GmsABD",
          "type": "group",
          "all_members_are_administrators": true
        },

Đã có chat ID
Bước 4:
Điền thông tin vào PRTG, truy cập PTRG, setup –> notify template
Sửa or add 1 template
Phần Execute HTTP Action
URL dạng: https://api.telegram.org/bot481775980:NAGtU-UYFQfYhufthedUAwMB2XWzRc8F6AA/sendMessage
HTTP Method: POST
Payload:

chat_id= số chat ID lấy được ở bước trên&text=
[%sensor](%linksensor)
*Last Value* %lastvalue
*Last Message* %lastmessage 
*Down since* %since
*Device* %device
*Group* %group&parse_mode=Markdown

Ví dụ hoàn chỉnh

chat_id=-359110891&text=
[%sensor](%linksensor)
*Last Value* %lastvalue
*Last Message* %lastmessage 
*Down since* %since
*Device* %device
*Group* %group&parse_mode=Markdown

Lưu tất cả lại.
Sau đó khi add trigger notifycation, chọn template này là OK

 

Simple monitoring – Chương trình monitor mạng đơn giản.

Chương trình được viết bằng python

Hướng dẫn cài đặt:

Cài đặt python3, và các gói cần thiết
yum install epel-release -y & yum install python36 python36-pip.noarch -y && pip3 install requests

Cách chạy app, sau khi thay cấu hình trong file config.py
cd <đường dẫn thư mục app>
python3 monitor_simple.py

Cách thiết lập chạy mỗi phút 1 lần:
crontab -l
Thêm vào dòng sau:
* * * * * /usr/bin/python3 <đường dẫn file monitor_simple.py>

Download:

https://github.com/khachuy2705/monitor_simple

Thêm custom rule firewall cho ESXi

Tương tự ufw, iptable của centos, ubuntu, ESXi cũng có firewall của riêng mình. Mặc định ESXi đã tạo sẵn 1 số rule, chúng ta có thể thao tác với các rule này trên web quản trị Tuy nhiên một có một số hạn chế như: chỉ đi ra ngoài qua outgoing port mặc định: 80, 22, 443.v.v Khi đó cần tạo thêm rule mới cho nhu cầu của mình. Cách mở thêm rule như sau: SSH vào máy chủ ESXi, sửa file /etc/vmware/firewall/custom.xml nếu không có thì tạo mới. Thêm rule vào theo định dạng sau:
<ConfigRoot>
  <service id='0100'>
    <id>sshClient-2222</id>
    <rule>
      <direction>outbound</direction>
      <protocol>tcp</protocol>
      <porttype>dst</porttype>
      <port>2222</port>
    </rule>
    <enabled>true</enabled>
    <required>false</required>
  </service>

  <service id='0101'>
    <id>NFSClient-2049</id>
    <rule>
      <direction>outbound</direction>
      <protocol>tcp</protocol>
      <porttype>dst</porttype>
      <port>2049</port>
    </rule>
    <enabled>true</enabled>
    <required>false</required>
  </service>

</ConfigRoot>
Sau đó refresh lại firewall
esxcli network firewall refresh
 

Hướng dẫn cài đặt centos 7 qua network PXE

PXE (Preboot eXecution Environment) Server cho phép cài đặt OS qua network, có thể thiết lập tự động chọn các cấu hình ban đầu khi cài đặt OS. Lợi ích chính của việc này đó là chúng ta có thể cài đặt server 1 lần, sau đó sử dụng để cài đặt một cách tự động cho hàng chục, thậm chí hàng trăm máy khác nhau mà không cần phải mất công burn file ISO sang USB hay DVD như trước đây.

Trong bài viết dưới đây chúng ta sẽ cài đặt 1 PXE server, phục vụ cài centos 7 cho máy khác.

Chi tiết:

  • Server IP = 192.168.150.11
  • Host name = pxe.example.com
  • OS = CentOS 7.x
  • SELinux = enabled
  • Firewall = disabled

Step:1 Cài đặt các gói cần thiết cho PXE

Các gói cần thiết: “dhcp, tftp-server, ftp server(vsftpd), xinted”.

[root@pxe ~]# yum install dhcp tftp tftp-server syslinux vsftpd xinetd vim -y

Step:2 Cấu hình DHCP

Sau khi cài đặt gói dhcp ở trên, chúng ta tạo file cấu hình cho  nó có nội dung dưới đây, các bạn có thể thay thế IP tương ứng vủa nhà mình vào.

[root@pxe ~]# vi /etc/dhcp/dhcpd.conf
# DHCP Server Configuration file.
ddns-update-style interim;
ignore client-updates;
authoritative;
allow booting;
allow bootp;
allow unknown-clients;
# internal subnet for my DHCP Server
subnet 192.168.150.0 netmask 255.255.255.0 {
range 192.168.150.21 192.168.150.151;
option domain-name-servers 192.168.150.11;
option domain-name "pxe.example.com";
option routers 192.168.150.11;
option broadcast-address 192.168.150.255;
default-lease-time 600;
max-lease-time 7200;
# IP of PXE Server
next-server 192.168.150.11;
filename "pxelinux.0";
}

 

Step:3 Cấu hình tftp server (/etc/xinetd.d/tftp)

TFTP (Trivial File Transfer Protocol ) is được sử dụng để tranfer file qua network mà không cần xác thực. Với PXE server, tftp được sử dụng cho bootstrap loading. Để cấu hình tftp server, sửa file ‘ /etc/xinetd.d/tftp’, thay đổi thông số ‘disable = yes‘ -> ‘disable = no’ và để nguyên đám còn lại mặc định, nội dung của nó sẽ tương tự như sau:

[root@pxe ~]# vi /etc/xinetd.d/tftp
service tftp
{
 socket_type = dgram
 protocol    = udp
 wait        = yes
 user        = root
 server      = /usr/sbin/in.tftpd
 server_args = -s /var/lib/tftpboot
 disable     = no
 per_source  = 11
 cps         = 100 2
 flags       = IPv4
}

Toàn bộ các file phục vụ cho việc boot qua network được đặt trong thư mục tftp root “/var/lib/tftpboot

Chạy các câu lênh sau để chép các file cần thiết vào ‘/var/lib/tftpboot/’

[root@pxe ~]# cp -v /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot
[root@pxe ~]# cp -v /usr/share/syslinux/menu.c32 /var/lib/tftpboot
[root@pxe ~]# cp -v /usr/share/syslinux/memdisk /var/lib/tftpboot
[root@pxe ~]# cp -v /usr/share/syslinux/mboot.c32 /var/lib/tftpboot
[root@pxe ~]# cp -v /usr/share/syslinux/chain.c32 /var/lib/tftpboot
[root@pxe ~]#
[root@pxe ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@pxe ~]# mkdir /var/lib/tftpboot/networkboot
root@pxe ~]#

Step:4 Mount ISO Centos 7 và copy tới thực mụcftp

Download file iso trên mạng, mount vào và copy cả folder vào thư mục sau ‘/var/ftp/pub

[root@pxe ~]# mount -o loop CentOS-7-x86_64-DVD-1511.iso /mnt/
mount: /dev/loop0 is write-protected, mounting read-only
[root@pxe ~]# cd /mnt/
[root@pxe mnt]# cp -av * /var/ftp/pub/

Copy Kernel file (vmlimz) và initrd file từ thư mục đã mount ở trên vào thư mục ‘/var/lib/tftpboot/networkboot/

[root@pxe ~]# cp /mnt/images/pxeboot/vmlinuz /var/lib/tftpboot/networkboot/
[root@pxe ~]# cp /mnt/images/pxeboot/initrd.img /var/lib/tftpboot/networkboot/
[root@pxe ~]#

Step:5 Create kickStart & PXE menu file.

Tạo 1 password được mã hoá, sẽ sử dụng sau này bằng lệnh dưới, thay cái 123@123a bằng pass của mình. Xong copy output lại, có việc cần tới.

[root@pxe ~]# openssl passwd -1 123@123a
$1$qwUUn.B3$Da8qxnXqxwh6zwBWrnE7/. 
[root@pxe ~]#

Default kickstart file được đặt tại /root với tên ‘anaconda-ks.cfg’. chúng ta sẽ tạo file kickstart mới tại  /var/ftp/pub với tên ‘centos7.cfg

Copy nội dung dưới ném vào file /var/ftp/pub/centos7.cfg

Thay thế cấu hình dòng rootpw –iscrypted bằng chuỗi pass mã hoá đã thực hiện ở trên.

[root@pxe ~]# vi /var/ftp/pub/centos7.cfg

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use FTP installation media
url --url="ftp://192.168.150.11/pub/"
# Root password
rootpw --iscrypted $1$e2wrcGGX$tZPQKPsXVhNmbiGg53MN41
# System authorization information
auth useshadow passalgo=sha512
# Use graphical install
graphical
firstboot disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux disabled
# Installation logging level
logging level=info
# System timezone
timezone Europe/Amsterdam
# System bootloader configuration
bootloader location=mbr
clearpart --all --initlabel
part swap --asprimary --fstype="swap" --size=1024
part /boot --fstype xfs --size=300
part pv.01 --size=1 --grow
volgroup root_vg01 pv.01
logvol / --fstype xfs --name=lv_01 --vgname=root_vg01 --size=1 --grow
%packages
@^minimal
@core
%end
%addon com_redhat_kdump --disable --reserve-mb='auto'
%end

Tạo PXE menu file (/var/lib/tftpboot/pxelinux.cfg/default), Copy nội dung bên dưới bỏ vào

[root@pxe ~]# vi /var/lib/tftpboot/pxelinux.cfg/default

[root@pxe ~]# vi /var/lib/tftpboot/pxelinux.cfg/default

default menu.c32
prompt 0
timeout 30
MENU TITLE LinuxTechi.com PXE Menu
LABEL centos7_x64
MENU LABEL CentOS 7_X64
KERNEL /networkboot/vmlinuz
APPEND initrd=/networkboot/initrd.img inst.repo=ftp://192.168.150.11/pub ks=ftp://192.168.150.11/pub/centos7.cfg

Step:6 Bật các dịch vụ

Sử dụng các lệnh dưới đây

[root@pxe ~]# systemctl start xinetd
[root@pxe ~]# systemctl enable xinetd
[root@pxe ~]# systemctl start dhcpd.service
[root@pxe ~]# systemctl enable dhcpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.
[root@pxe ~]# 
[root@pxe ~]# systemctl start vsftpd
[root@pxe ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
[root@pxe ~]#
[root@pxe ~]# setsebool -P allow_ftpd_full_access 1
[root@pxe ~]#

 

Mở port cho firewall

[root@pxe ~]# firewall-cmd --add-service=ftp --permanent
success
[root@pxe ~]# firewall-cmd --add-service=dhcp --permanent
success
[root@pxe ~]# firewall-cmd --add-port=69/tcp --permanent 
success
[root@pxe ~]# firewall-cmd --add-port=69/udp --permanent 
success
[root@pxe ~]# firewall-cmd --add-port=4011/udp --permanent
success
[root@pxe ~]# firewall-cmd --reload
success
[root@pxe ~]#

 

Nếu lười quá, thì cứ stop firewall lại là xong, cho đỡ rách việc

systemctl disable –now firewalld

Step:7 Boot the clients with pxe boot option.

Dưới đây là video hướng dẫn thực hiện

Active office 2019 không cần dùng phần mềm

Bước 1: Mở notepad, paste nội dung sau và lưu lại dưới tên active.cmd

@echo off
title Kich hoat Microsoft Office 2019 ALL versions mienphi!&cls&echo ============================================================================&echo #Kich hoat Microsoft Office 2019 hop phap - Khong su dung phan mem&echo ============================================================================&echo.&echo #San pham ho tro:&echo - Microsoft Office Standard 2019&echo - Microsoft Office Professional Plus 2019&echo.&echo.&(if exist "%ProgramFiles%\Microsoft Office\Office16\ospp.vbs" cd /d "%ProgramFiles%\Microsoft Office\Office16")&(if exist "%ProgramFiles(x86)%\Microsoft Office\Office16\ospp.vbs" cd /d "%ProgramFiles(x86)%\Microsoft Office\Office16")&(for /f %%x in ('dir /b ..\root\Licenses16\ProPlus2019VL*.xrm-ms') do cscript ospp.vbs /inslic:"..\root\Licenses16\%%x" >nul)&(for /f %%x in ('dir /b ..\root\Licenses16\ProPlus2019VL*.xrm-ms') do cscript ospp.vbs /inslic:"..\root\Licenses16\%%x" >nul)&echo.&echo ============================================================================&echo Activating your Office...&cscript //nologo ospp.vbs /unpkey:6MWKP >nul&cscript //nologo ospp.vbs /inpkey:NMMKJ-6RK4F-KMJVX-8D9MJ-6MWKP >nul&set i=1
:server
if %i%==1 set KMS_Sev=kms7.MSGuides.com
if %i%==2 set KMS_Sev=kms8.MSGuides.com
if %i%==3 set KMS_Sev=kms9.MSGuides.com
if %i%==4 set KMS_Sev=kms.digiboy.ir
if %i%==5 goto notsupported
cscript //nologo ospp.vbs /sethst:%KMS_Sev% >nul&echo ============================================================================&echo.&echo.
cscript //nologo ospp.vbs /act | find /i "successful" && (echo.&echo ============================================================================&choice /n /c YN /m "Truy cap devopsvn.xyz: [Y,N]?" & if errorlevel 2 exit) || (echo Ket noi voi may chu KMS khong thanh cong! Dang ket noi lai... & echo Vui long cho... & echo. & echo. & set /a i+=1 & goto server)
explorer "https://devopsvn.xyz"&goto halt
:notsupported
echo.&echo ============================================================================&echo Phien ban Office cua ban khong duoc ho tro.&echo Download phien ban moi nhat tai day: http://devopsvn.xyz/:halt
pause >nul

Bước 2: mở file active.cmd vừa tạo dưới quyền administrator và ngồi chờ. Thành công sẽ báo

Hướng dẫn cài đặt oracle client trên redhat 7 – How to install oracle client 12 on redhat

Chuẩn bị:
– Redhat enterprise 7, có thể cài thêm repo: https://devopsvn.xyz/cai-dat-centos-repo-cho-redhat-rhel-7/

– Bộ cài Oracle client 12: https://www.oracle.com/technetwork/database/enterprise-edition/downloads/oracle12c-linux-12201-3608234.html

Trên máy chủ linux, cài đặt các gói: unzip, gcc

yum install -y gcc unzip

Download bộ cài client: linuxx64_12201_client.zip

Giải nén bộ cài, ta được thư mục client

[root@testora opt]# tree -L 3
.
├── client
│   ├── install
│   │   └── ***********
│   ├── response
│   │   ├── client_install.rsp  #File response, cấu hình cho quá trình cài đặt
│   │   └── netca.rsp
│   ├── runInstaller # File cài đặt
│   ├── stage
│   │   ├── **********
│   └── welcome.html
└── linuxx64_12201_client.zip

Mở file response/client_install.rsp và thiết lập các thông số như sau:

UNIX_GROUP_NAME=oracle
INVENTORY_LOCATION=/u01/oracle/ora_inventory
ORACLE_HOME=/u01/oracle/client_v12.2_base/home
ORACLE_BASE=/u01/oracle/client_v12.2_base
oracle.install.client.installType=Administrator

Một số lưu ý:
INVENTORY_LOCATION : đường dẫn thư mục này phải khác với đường dẫn cho ORACLE_HOME và ORACLE_BASE

đường dẫn ORACLE_HOME nên nằm bên trong ORACLE_BASE

oracle.install.client.installType nên để Administrator, sau này sẽ có nhiều tùy chỉnh hơn.

UNIX_GROUP_NAME: Oracle client không cài được dưới user root, nên phải tạo user khác cho nó, group tương ứng với user đó là gì thì điền vào đây, Group này phải có quyền đọc ghi , exec tất cả các đường dẫn đã khai báo trên. (dùng đường dẫn nào thì vào chown cho nó)

Sau khi khai báo, đứng ở thư mục chứa file runInstaller ở trên, chạy:

./runInstaller -silent -responseFile /opt/client/response/client_install.rsp</span>

Nhớ thay đường dẫn đúng vào file client_install.rsp ở trên.

Sau khi chạy, sẽ hiển thị dạng:

[oracle@testora client]$ ./runInstaller -silent -responseFile /opt/client/response/client_install.rsp
Starting Oracle Universal Installer...

Checking Temp space: must be greater than 415 MB.   Actual 32130 MB    Passed
Checking swap space: must be greater than 150 MB.   Actual 3967 MB    Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2019-06-22_01-52-44PM. Please wait ...
[oracle@testora client]$
[oracle@testora client]$
[oracle@testora client]$ [WARNING] [INS-13014] Target environment does not meet some optional requirements.
   CAUSE: Some of the optional prerequisites are not met. See logs for details. installActions2019-06-22_01-52-44PM.log
   ACTION: Identify the list of failed prerequisite checks from the log: installActions2019-06-22_01-52-44PM.log. Then either from the log file or from installation manual find the appropriate configuration to meet the prerequisites and fix it manually.
You can find the log of this install session at:
 /u01/oracle/ora_inventory/logs/installActions2019-06-22_01-52-44PM.log
The installation of Oracle Client 12c was successful.
Please check '/u01/oracle/ora_inventory/logs/silentInstall2019-06-22_01-52-44PM.log' for more details.

As a root user, execute the following script(s):
        1. /u01/oracle/ora_inventory/orainstRoot.sh



Successfully Setup Software.

[oracle@testora client]$

Làm theo hướng dẫn, chuyển qua user root, chạy /u01/oracle/ora_inventory/orainstRoot.sh là xong.

 

 

Cài đặt centos repo cho redhat rhel 7

Case: Cài đặt redhat enteprise, chưa active gì, trong máy không có repo nào để cài gói cơ bản, mở /etc/yum.repo.d rỗng.

Để cài đặt centos repo cho redhat, tiền hành làm như sau:
Tạo file mới có định dạng .repo ví dụ Centos.repo trong thư mục /etc/yum.repo.d

Nội dung:

[centos]
name=CentOS-7
baseurl=http://ftp.heanet.ie/pub/centos/7/os/x86_64/
enabled=1
gpgcheck=1
gpgkey=http://ftp.heanet.ie/pub/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7

Sau đó lưu lại dưới tên Centos-Base.repo
Tiếp tục chạy lệnh:

yum repolist
Tiếp theo đã có thể cài đặt các gói bằng yum

Print Spooler Error code 3. The system cannot find the path specified

Xử lý lỗi:

Print Spooler Error code 3. The system cannot find the path specified

Không thể start service print spooler, báo lỗi như trên, mở properties của service thì thấy execute path không có gì. Có thể xử lý như sau:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Spooler registry key and right-click Spooler > New > Expandable String Value > then name the value ImagePath then double-click ImagePath and type (or copy and paste) the following under "Value data":

%SystemRoot%\System32\spoolsv.exe

Then press "OK"

Close regedit and see if you can start the Print Spooler service.

Returning Blanks with VLOOKUP

When you use VLOOKUP to return a value from a data table, the function does not differentiate between blanks and zero values in what it returns. If the source value is zero, then VLOOKUP returns 0. Likewise, if the source is blank, then VLOOKUP still returns the value 0. For some purposes, this may not do—you need to know whether the cell being looked up is blank or if it really contains a 0.

There are many different solutions that could be pursued. One solution relies on the fact that even though VLOOKUP returns a 0, it will correctly report the length of the source cell. Thus, if you use the LEN function on what is returned, if the source cell is empty the LEN function returns 0, but if the source contains a 0 then LEN returns 1 (the 0 value is 1 character in length). This means that you could use the following formula in place of a standard VLOOKUP:

=IF(LEN(VLOOKUP(B1,D:E,2,0))=0,””,VLOOKUP(B1,D:E,2,0))

In this case if the length of what VLOOKUP returns is 0, then Excel doesn’t actually do a lookup—it forces a blank to be returned. Only if the length is not 0 is the actual VLOOKUP performed.

There are other variations on this same concept, each testing a different characteristic of the data being referenced and then making the decision as to whether to actually look up that data. This variation, for example, directly tests to see if the source is blank:

=IF(VLOOKUP(B1,D:E,2)=””,””,VLOOKUP(B1,D:E,2))

The formula can also be modified to check the source cell for multiple conditions. For instance, this variation returns a blank if the source is blank or if the source contains an #N/A error:

=IF(ISNA(VLOOKUP(B1,D:E,2,0))+(VLOOKUP(B1,D:E,2,0)=””)

,””,VLOOKUP(B1,D:E,2,0))


Notice: ob_end_flush(): failed to send buffer of zlib output compression (0) in /home/devopsvn/public_html/wp-includes/functions.php on line 5427