Tuesday, June 9, 2015

Steps to delete a defunct nagios host from centreon mysql database

If you have deleted a Centreon host from GUI but still is shows in Centreon monitoring service status, you may need to clean up host and related services from MySQl DB.

Below is steps to delete a dead host. If select statement do not return any record, obviously, corresponding delete is not required.


# mysqld
myysql> connect centreon_status;

myysql> SELECT host_id        FROM nagios_hosts WHERE display_name LIKE '%deadsystem01%';
myysql> SELECT host_object_id FROM nagios_hosts WHERE display_name= 'deadsystem01';
myysql> SELECT *              FROM nagios_hosts WHERE display_name = 'deadsystem01';

myysql> DELETE from nagios_hosts WHERE  display_name = 'deadsystem01';


myysql> SELECT * FROM nagios_objects WHERE name1 = 'deadsystem01';
myysql> DELETE   FROM nagios_objects WHERE name1 = 'deadsystem01';


myysql> SELECT * FROM nagios_hostgroup_members WHERE host_object_id = '123456';
myysql> DELETE   FROM nagios_hostgroup_members WHERE host_object_id = '123456';


myysql> SELECT * FROM nagios_hosts WHERE host_object_id = '123456';
myysql> DELETE   FROM nagios_hosts WHERE host_object_id = '123456';


myysql> SELECT * FROM nagios_hoststatus WHERE host_object_id = '123456';
myysql> DELETE   FROM nagios_hoststatus WHERE host_object_id = '123456';


myysql> SELECT * FROM nagios_objects WHERE name1 = 'deadsystem01';
myysql> DELETE   FROM nagios_objects WHERE name1 = 'deadsystem01';


myysql> SELECT service_object_id FROM nagios_services WHERE host_object_id = '123456';
myysql> DELETE FROM nagios_services WHERE host_object_id = '123456';


myysql> SELECT * FROM nagios_servicestatus WHERE service_object_id = '$above_id';
myysql> DELETE   FROM nagios_servicestatus WHERE service_object_id = '$above_id';





Puppet : how to append a string as new item into existing array ?

What is hiera?


Hiera is simple Lightweight Pluggable Hierarchical Database. It is a key/value lookup tool for hiera_lookupiguration data. Key/value may be string, array or hash.

Using Hiera


Suppose you have a a_hiera_hash in your yaml. It has a_hiera_key in two different yaml. At one place it is string ( hiera/location/dc1.yaml ) and at another place it is array (hiera/location/dc2.yaml)

==> hiera/location/dc1.yaml

a_hiera_hash:
    a_hiera_key: item_string


==> hiera/location/dc2.yaml

a_hiera_hash:
    a_hiera_key:
        - item_one
        - item_two
        - item_three


Adding a string in a string or array returned by hiera_hash


Now, if you want to add another string 'item_string_2' at the end of a_hiera_hash, there are 2 cases:

Case-1:

system1.dc1.com - a system in DC1 - For this system, a_hiera_key will be evaluated as string.

hiera_lookup = hiera_hash('a_hiera_hash', {})
hiera_lookup['a_hiera_key'] = 'item_string'  << this is what we will get

So we need to add 'item_string_2' at the end of above string. Puppet code will look like below.

        $a_hiera_key = $hiera_lookup['a_hiera_key']
        $a_hiera_key_new = "${a_hiera_key} item_string_2"
        $a_hiera_key = $a_hiera_key_new


Case-1:

system2.dc2.com - a system in DC2 - For this system, a_hiera_key will be evaluated as array.

hiera_lookup = hiera_hash('a_hiera_hash', {})
a_hiera_hash['a_hiera_key'] = [ 'item_one', 'item_two', 'item_three' ] << this is what we will get

So, now we need to add 'item_string_2' string as a new item of above array ! (type mismatch)


There is no straight way to add string as a new item of array item ! 

1- Convert array item into space seprated string using join library function - 'item_one item_two item_three'

        $a_hiera_key = join($hiera_lookup['a_hiera_key'], ' ')


2- Add 'item_string_2' at the end of string - 'item_one item_two item_three item_string_2'

        $a_hiera_key_new = "${a_hiera_key} item_string_2"

3- Split string using space a separator to make an array using split function- [ 'item_one', 'item_two', 'item_three', 'item_string_2' ]

         $a_hiera_key = split($a_hiera_key_new, ' ')



So, puppet code will look like something this.

hiera_lookup = hiera_hash('a_hiera_hash', {})

      if is_array($hiera_lookup['a_hiera_key']) {
        $a_hiera_key = join($hiera_lookup['a_hiera_key'], ' ')
        $a_hiera_key_new = "${a_hiera_key} item_string_2"
        $a_hiera_key = split($a_hiera_key_new, ' ')
      } else {
        $a_hiera_key = $hiera_lookup['a_hiera_key']
        $a_hiera_key_new = "${a_hiera_key} item_string_2"
        $a_hiera_key = $a_hiera_key_new
      }


NOTE:
If dc1.yaml also has array (similar to dc2.yaml), hiera_has will automatically merge 2 arrays. For eacmple, if dc1.yaml array is following

a_hiera_hash:
    a_hiera_key:
        - item_dc1


Then, a_hiera_key will be merge as below.

hiera_lookup = hiera_hash('a_hiera_hash', {})
a_hiera_hash['a_hiera_key'] = [ 'item_one', 'item_two', 'item_three', 'item_dc1'] << this is what we will get

References:
https://github.com/puppetlabs/hiera (hiera)
https://docs.puppetlabs.com/hiera/1/lookup_types.html (hiera_hash)
https://docs.puppetlabs.com/references/latest/function.html (split)
https://forge.puppetlabs.com/puppetlabs/stdlib/readme (join)


Saturday, June 6, 2015

Veritas storage foundation and replication manula stop and start steps

If we need to stop and start Veritas Storage Foundation and Veritas Replication to avoid reboot, below steps should work.


Steps to stop

umount /some/vxfs/filesystems
service vxfs_replication stop
service vxodm stop
service vxdbdctrl stop
service vxpbx_exchanged stop
service vxrsyncd.sh stop
service vxnm-vxnetd stop
service vxfs stop
service vxvm-boot stop

Steps to start


service vxfs start
service vxvm-boot start
service vxpbx_exchanged start
service vxnm-vxnetd start
service vxdbdctrl start
service vxvm-reconfig start
service vxvm-recover start
service vxodm start
service vxrsyncd.sh start
service vxfs_replication start
mount /some/vxfs/filesystems