Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Friday, 21 September 2018

Zabbix API create item using CURL

Zabbix allow to create and configure items using API. It faster than clicking using GUI.

On this example I use CURL to call api.
First you need to generate token to identifying you credentials.



Check API version

curl  -H "Content-Type: application/json-rpc" -X POST  http://zabbix/zabbix/api_jsonrpc.php -d '{"jsonrpc":"2.0","method":"apiinfo.version","id":1,"auth":null,"params":{}}'


Generate API token


curl -i -X POST -H 'Content-type:application/json' -d '{"jsonrpc":"2.0","method":"user.login","params":{ "user":"adm***","password":"****"},"auth":null,"id":0}' http://zabbix/zabbix/api_jsonrpc.php


Check host ID not using API


Login to zabbix and show configuration of you host, ID of this host will be in URL address

It is a simplest way to find your host ID.


Prepare new item using existing item 


Creating item require id of host and id of interface which is used to check item.
When you know the host ID you can create simple item from interface and next create item based on existing item.

To get configuration of item you need to specify item.key

Simple json file to call api:

{
    "jsonrpc": "2.0",
    "method": "item.get",
    "params": {
        "output": "extend",
        "hostids": "10336",
        "search": {
            "key_": "system.uptime"
        },
        "sortfield": "name"
    },
    "auth": "193ab2b48e6c428477869f6dcfa4dd26",
    "id": 1
}

10336 - is your hostid
system.uptime - is you item.key which you want to show
auth - your token genarated in step generate api token.

Save you file as js.json and call

curl -i -X POST -H 'Content-type:application/json' -d @js.json http://zabbix/zabbix/api_jsonrpc.php



Your output should look like this

{
  "jsonrpc": "2.0",
  "result": [
    {
      "itemid": "54816",
      "type": "0",
      "snmp_community": "",
      "snmp_oid": "",
      "hostid": "10336",
      "name": "System uptime",
      "key_": "system.uptime",
      "delay": "1m",
      "history": "1w",
      "trends": "365d",
      "status": "0",
      "value_type": "3",
      "trapper_hosts": "",
      "units": "uptime",
      "snmpv3_securityname": "",
      "snmpv3_securitylevel": "0",
      "snmpv3_authpassphrase": "",
      "snmpv3_privpassphrase": "",
      "formula": "",
      "error": "",
      "lastlogsize": "0",
      "logtimefmt": "",
      "templateid": "23150",
      "valuemapid": "0",
      "params": "",
      "ipmi_sensor": "",
      "authtype": "0",
      "username": "",
      "password": "",
      "publickey": "",
      "privatekey": "",
      "mtime": "0",
      "flags": "0",
      "interfaceid": "219",
      "port": "",
      "description": "",
      "inventory_link": "0",
      "lifetime": "30d",
      "snmpv3_authprotocol": "0",
      "snmpv3_privprotocol": "0",
      "state": "0",
      "snmpv3_contextname": "",
      "evaltype": "0",
      "jmx_endpoint": "",
      "master_itemid": "0",
      "lastclock": "1537556736",
      "lastns": "842421756",
      "lastvalue": "13830471",
      "prevvalue": "13830411"
    }
  ],
  "id": 1
}

From this values you can check important keys:
itemid
interfaceid
and many others

Now you can customize and create your new item.


Create new item (with using SNMP)


Create json file  item.json:
 
{
"jsonrpc": "2.0",
"method": "item.create",
"params": {
"name": "Active_Connection",
"key_": "Active_Connection",
"hostid": "10336",
"delay": "60s",
"history": "90d",
"type": 1,
"trends": "365d",
"status": "0",
"value_type": "3",
"snmp_oid": "1.3.6.1.4.1.140.625.190.1.25.16.18.144.146.180.197.194.18.77.60.51.78.5.246.62.52.18",
"snmp_community": "public",
"interfaceid": "219",
"port": "1161"
},
"auth": "e8a754b6fb4c55932bc6205dac3af55a",
"id": 0
}

And run


curl -i -X POST -H 'Content-type:application/json' -d @item.json http://zabbix/zabbix/api_jsonrpc.php


Friday, 14 September 2018

Zabbix monitoring Oracle database using orabbix - working example Oracle 12c

Orabbix


Orabix use jdbc connection to database so it not require installation of additional packages on database server.

Unzip downloaded Orabbix 1.2.3 file to /opt/orabbix (on zabbix server)

Copy file /opt/orabbix/init.d/orabbix to /etc/init.d/orabbix

Grant execute permissions to the following files:

 /etc/init.d/orabbix
 /opt/orabbix/run.sh


Create zabbix user on oracle database

CREATE USER ZABBIX
IDENTIFIED BY <REPLACE WITH PASSWORD>
DEFAULT TABLESPACE USERS
TEMPORARY TABLESPACE TEMP
PROFILE DEFAULT
ACCOUNT UNLOCK;
GRANT ALTER SESSION TO ZABBIX;
GRANT CREATE SESSION TO ZABBIX;
GRANT CONNECT TO ZABBIX;
ALTER USER ZABBIX DEFAULT ROLE ALL;
GRANT SELECT ON V_$INSTANCE TO ZABBIX;
GRANT SELECT ON DBA_USERS TO ZABBIX;
GRANT SELECT ON V_$LOG_HISTORY TO ZABBIX;
GRANT SELECT ON V_$PARAMETER TO ZABBIX;
GRANT SELECT ON SYS.DBA_AUDIT_SESSION TO ZABBIX;
GRANT SELECT ON V_$LOCK TO ZABBIX;
GRANT SELECT ON DBA_REGISTRY TO ZABBIX;
GRANT SELECT ON V_$LIBRARYCACHE TO ZABBIX;
GRANT SELECT ON V_$SYSSTAT TO ZABBIX;
GRANT SELECT ON V_$PARAMETER TO ZABBIX;
GRANT SELECT ON V_$LATCH TO ZABBIX;
GRANT SELECT ON V_$PGASTAT TO ZABBIX;
GRANT SELECT ON V_$SGASTAT TO ZABBIX;
GRANT SELECT ON V_$LIBRARYCACHE TO ZABBIX;
GRANT SELECT ON V_$PROCESS TO ZABBIX;
GRANT SELECT ON DBA_DATA_FILES TO ZABBIX;
GRANT SELECT ON DBA_TEMP_FILES TO ZABBIX;
GRANT SELECT ON DBA_FREE_SPACE TO ZABBIX;
GRANT SELECT ON V_$SYSTEM_EVENT TO ZABBIX;


 exec dbms_network_acl_admin.create_acl(acl => 'resolve.xml',description => 'resolve acl', principal =>'ZABBIX', is_grant => true, privilege => 'resolve');
 exec dbms_network_acl_admin.assign_acl(acl => 'resolve.xml', host =>'*');
 commit;


To verify connect to database as user zabbix and run sql

sqlplus zabbix/<REPLACE WITH PASSWORD>@database_service
select utl_inaddr.get_host_name('127.0.0.1') from dual;

(on RHEL6)
chkconfig -add orabbix



(on Debian) change line in file
/etc/init.d/orabbix 
from 
. /etc/rc.d/init.d/functions
to
. /lib/lsb/init-functions
 

Download from Oracle latest ojdbc6 driver and copy it to location /opt/orabbix/lib (overwrite existig file)


Example config.props (my db is rr01dev, zabbix server ip 192.168.41.194,
#comma separed list of Zabbix servers
ZabbixServerList=ZabbixServer1

ZabbixServer1.Address=192.168.41.194
ZabbixServer1.Port=10051

#pidFile
OrabbixDaemon.PidFile=./logs/orabbix.pid
#frequency of item's refresh
OrabbixDaemon.Sleep=300
#MaxThreadNumber should be >= than the number of your databases
OrabbixDaemon.MaxThreadNumber=100

#put here your databases in a comma separated list
DatabaseList=rr01dev

#Configuration of Connection pool
#if not specified Orabbis is going to use default values (hardcoded)
#Maximum number of active connection inside pool
DatabaseList.MaxActive=10
#The maximum number of milliseconds that the pool will wait
#(when there are no available connections) for a connection to be returned
#before throwing an exception, or <= 0 to wait indefinitely.
DatabaseList.MaxWait=100
DatabaseList.MaxIdle=1

#define here your connection string for each database
rr01dev.Url=jdbc:oracle:thin:@sc-test-001:1524/rr01dev
rr01dev.User=zabbix
rr01dev.Password=*****
#Those values are optionals if not specified Orabbix is going to use the general values
rr01dev.MaxActive=10
rr01dev.MaxWait=100
rr01dev.MaxIdle=1
rr01dev.QueryListFile=./conf/query.props



Database name must be the same as host in zabbix

Run script
/opt/orabbix/run.sh

And check for errors file
/opt/orabbix/logs/orabbix.log

When you have error with connection check if ListenPort=10051 is uncomented
/etc/zabbix/zabbix_server.conf
ListenPort=10051


Import templates from /opt/orabbix/templates to zabbix using gui

And create host

Apply template
Go to graph find your host and check if orabbix working properly

Tested on zabbix 3.4






Monday, 13 January 2014

FC target configuration - Targetcli as open source SAN (debian)

Installation on debian wheezy with kernel 3.10.25

Download rpm
apt-get install targetcli 

Or install without recommended packages
apt-get install --no-install-recommends targetcli

Create file for datastore
dd if=/dev/zero of=/opt/test1 bs=1024 count=6000000



targetcli

Create datastore on targetcli
cd backstores/fileio
create itest1 /opt/test1 6144000000B

Create iSCSCI target instance
cd /iscsi
create

Map LUN to datastore (based on FILEIO)
cd luns
create /backstores/fileio/itest1

Configure ACL (check WWN in openiscsi section)
cd ../../acls
create
create iqn.1993-08.org.debian:01:dcb3d359cc91

Save configuration
cd /
saveconfig

Disable athentication
cd iscsi/
set set discovery_auth enable=0
cd /iscsi/iqn.2003-01.org.linux-iscsi.sc-azl-001.x8664:sn.8b4b5e8c13a2/tpgt1
set attribute authentication=0

Configure interface
cd portals
create
cd /
saveconfig
All config should looks like:

targetcli
ls
o- / ......................................................................................................... [...]
  o- backstores .............................................................................................. [...]
  | o- fileio ................................................................................... [1 Storage Object]
  | | o- idisk ............................................................................. [/opt/test1 activated]
  | o- iblock ................................................................................... [0 Storage Object]
  | o- pscsi .................................................................................... [0 Storage Object]
  | o- rd_dr .................................................................................... [0 Storage Object]
  | o- rd_mcp ................................................................................... [0 Storage Object]
  o- iscsi .............................................................................................. [1 Target]
  | o- iqn.2003-01.org.linux-iscsi.sc-azl-001.x8664:sn.8b4b5e8c13a2 ........................................ [1 TPG]
  |   o- tpgt1 ........................................................................................... [enabled]
  |     o- acls ........................................................................................... [1 ACLs]
  |     | o- iqn.1993-08.org.debian:01:dcb3d359cc91 ................................................. [1 Mapped LUN]
  |     |   o- mapped_lun0 ............................................................................. [lun0 (rw)]
  |     o- luns ............................................................................................ [1 LUN]
  |     | o- lun0 ..................................................................... [fileio/idisk (/home/test1)]
  |     o- portals ...................................................................................... [1 Portal]
  |       o- 192.168.42.135:3260 .............................................................................. [OK]
  o- loopback ........................................................................................... [0 Target]
  o- qla2xxx ............................................................................................ [0 Target]
  o- tcm_fc ............................................................................................. [0 Target]


OpeniSCSI installation - client (initiatior)

aptitude install open-iscsi
/etc/init.d/open-iscsi restart

Search target name:
iscsiadm -m discovery -t sendtargets -p 192.168.42.135

Check your initiator name

cat /etc/iscsi/initiatorname.iscsi
## DO NOT EDIT OR REMOVE THIS FILE!
## If you remove this file, the iSCSI daemon will not start.
## If you change the InitiatorName, existing access control lists
## may reject this initiator.  The InitiatorName must be unique
## for each iSCSI initiator.  Do NOT duplicate iSCSI InitiatorNames.
InitiatorName=iqn.1993-08.org.debian:01:dcb3d359cc91



iscsiadm -m node

Connect to iscsi target:
iscsiadm -m node --targetname "iqn.2003-01.org.linux-iscsi.sc-azl-001.x8664:sn.8b4b5e8c13a2" --portal "192.168.42.135:3260" --login

Verify new block device
dmesg | tail

Debian wheezy kernel upgrade to 3.10 installation

Install packages needed to compile:

apt-get install fakeroot build-essential ncurses-dev

Download and unpack kernel

wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.10.25.tar.bz2
tar -xvf linux-3.10.25.tar.bz2
cd linux-3.10.25/

Configure kernel base on old configuration
cat /boot/config-`uname -r` > .config
cat .config
make oldconfig
make menuconfig

Compile kernel

time make deb-pkg -j2

Install
dpkg -i ../linux-firmware-image_3.10.25-1_amd64.deb ../linux-headers-3.10.25_3.10.25-1_amd64.deb ../linux-libc-dev_3.10.25-1_amd64.deb ../linux-image-3.10.25_3.10.25-1_amd64.deb
apt-cache policy linux-libc-dev

restart debian

Tuesday, 25 September 2012

Loop xargs

$ find . -iname "*.mp3" -print0 | xargs -0 -I mp3file mplayer mp3file

Connect to iscsi disk debian

List device
iscsiadm -m discovery -t st -p 192.168.42.236

192.168.42.236:3260,1 iqn.2012-08.sc-nas-004.istgt:disk1

Connect:
iscsiadm -m discovery -t st -p 192.168.42.236 "iqn.2012-08.sc-nas-004.istgt:disk2" --portal "192.168.42.236:3260" --login

Monday, 24 September 2012

Rman backup script

#!/bin/bash

export ORACLE_SID=orcl_1
export ORACLE_BASE=/u01/app/oracle
export PATH=/u01/app/oracle/database/product/11.2.0/dbhome_1/bin:/u01/app/11.2.0/grid/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/oracle/bin
export ORACLE_HOME=/u01/app/oracle/database/product/11.2.0/dbhome_1

basedir=/u01/app/oracle/backup
host=`hostname`
backup_dir=`date '+%Y.%m.%d'`

filename=`date '+%Y.%m.%d_%H.%M.%S'`

test -d ${basedir}/${host}/${backup_dir} || mkdir -p ${basedir}/${host}/${backup_dir}


if [ "x$1" = "x0" -o "x$1" = "x1" ]; then
inclevel=$1

rman target / log=${basedir}/${host}/${backup_dir}/backup_${filename}.log << !
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level ${inclevel} database format '${basedir}/${host}/${backup_dir}/data_lv${inclevel}_${filename}.%U';
backup as compressed backupset archivelog all delete all input format '${basedir}/${host}/${backup_dir}/arch_${filename}.%U';
backup as compressed backupset current controlfile format '${basedir}/${host}/${backup_dir}/control_${filename}.%U';
backup spfile format '${basedir}/${host}/${backup_dir}/spfile_${filename}.%U';
delete noprompt obsolete recovery window of 7 days;
}
!

else

rman target / log=${basedir}/${host}/${backup_dir}/backup_${filename}.log << !
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup as compressed backupset archivelog all delete all input format '${basedir}/${host}/${backup_dir}/arch_${filename}.%U';
backup as compressed backupset current controlfile format '${basedir}/${host}/${backup_dir}/control_${filename}.%U';
backup spfile format '${basedir}/${host}/${backup_dir}/spfile_${filename}.%U';
delete noprompt obsolete recovery window of 7 days;
}
!

fi

Friday, 4 November 2011

Zamiana ciągu znaków w plikach o podanej nazwie

Aby zmienić ciąg znakow w plikach o nazwie name*, można użyć poniższego polecenia.

find . -name 'name*' -exec sed -i 's/first/second/g' '{}' \;

Można dodać opcję wyszukiwania w plikach
find . -type f -name '*.xdo' -exec sed -i 's/first/second/' '{}' \;

Wednesday, 8 June 2011

Wykrywanie nowego dysku, skanowanie scsi

# echo "- - -" > /sys/class/scsi_host/host0/scan

Aby wykryć nowododany dysk należy użyc powyższej komendy

Tuesday, 24 May 2011

Sprawdzenie który proces korzysta z dysku

Sposób jest dobry gdy chcemy sprawdzić czemu nie działa umount

# fuser -m /dev/sdc1
/dev/sdc1: 538
# ps auxw|grep 538



Innym sposobem wyświetlenia plików aktualnie używanych jest użycie polecenia 


# lsof | grep ścieżka

Wednesday, 20 April 2011

Wylistowanie zawartości wszystkich zasobów zamontowanych w systemie

df -h | awk '{ print $6}' | tail -10 | xargs ls

w esx nie ma seda - tail można zastąpić sed -d1 aby pominąć nagłowek