Monday, March 14, 2016

OMD: python problem after CentOS yum update

After yum update I got a problem, related to python, with check_mk in the OMD implementation.

Environment:

  • CentOS 7
  • check_mk 1.2.4p5
  • omd-1.20


In the check_mk web page you can see a lot of messages like this in each "Check_MK inventory" check.

(Return code of 5 is out of bounds)

and if you issue the check_mk command you get

Cannot read file /omd/sites/prod/share/check_mk/modules/check_mk_base.py: 'frozenset' object is not callable

My solution was:

cp /omd/versions/1.20/lib/python/hashlib.py /omd/versions/1.20/lib/python/hashlib.py.OLD

cp /usr/lib64/python2.7/hashlib.py /omd/versions/1.20/lib/python/hashlib.py

Wednesday, February 10, 2016

SmartOS: how to clone a KVM machine

Get the disk0 filesystem of the VM to clone.

vmadm get uuid-originvm | json disks

[
  {
    "path": "/dev/zvol/rdsk/zones/uuid-originvm-disk0",
    "boot": true,
    "model": "virtio",
    "media": "disk",
    "image_size": 10240,
    "image_uuid": "d8e65ea2-1f3e-11e5-8557-6b43e0a88b38",
    "zfs_filesystem": "zones/uuid-originvm-disk0",
    "zpool": "zones",
    "size": 10240,
    "compression": "off",
    "refreservation": 10240,
    "block_size": 8192
  }
]

Take a snapshot

zfs snapshot zones/uuid-originvm-disk0@toclone

Create a json file in order to create the new VM.
vi targetvm.json
Please note: there are no disks.

{
  "alias": "targetvm",
  "hostname": "targetvm",
  "dns_domain": "mydomain.it",
  "brand": "kvm",
  "resolvers": [
    "192.168.0.2"
  ],
  "ram": "2048",
  "vcpus": "2",
  "nics": [
    {
      "nic_tag": "admin",
      "ip": "192.168.0.201",
      "netmask": "255.255.255.0",
      "gateway": "192.168.0.1",
      "model": "virtio",
      "primary": true
    }
  ]
}

vmadm create -f targetvm.json

Let's clone the filesystem of the origin VM.

zfs clone zones/uuid-originvm-disk0@toclone zones/uuid-targetvm-disk0

Create a json in order to add a disk to the new VM.
vi adddisk.json

{
   "add_disks": [
      {
          "media": "disk",
          "model": "virtio",
          "boot": true,
          "nocreate": true,
          "size": 10240,
          "path": "/dev/zvol/rdsk/zones/435ca788-4935-ead3-f4e4-94e6eb7dd4b6-disk0"
      }
   ]
}

Let's add the disk to the newly created VM.

vmadm stop uuid-targetvm -F

vmadm update uuid-targetvm -f adddisk.json

This is important.

zfs promote  zones/uuid-targetvm-disk0

From man zfs:

zfs promote clone-filesystem

    Promotes a clone file system to no longer be dependent on its "ori-
    gin" snapshot. This makes it possible to destroy  the  file  system
    that  the clone was created from. The clone parent-child dependency
    relationship is reversed, so that the origin file system becomes  a
    clone of the specified file system.

    The  snapshot  that  was cloned, and any snapshots previous to this
    snapshot, are now owned by the promoted clone. The space  they  use
    moves  from the origin file system to the promoted clone, so enough
    space must be available to  accommodate  these  snapshots.  No  new
    space  is  consumed  by this operation, but the space accounting is
    adjusted. The promoted clone must not have any conflicting snapshot
    names  of  its own. The rename subcommand can be used to rename any
    conflicting snapshots.

Tuesday, January 19, 2016

mod_jk apache 2.4 smartos zone

If, compiling mod_jk, you get

/usr/bin/bash: ../build/libtool: No such file or directory

Then

cd native/
./configure --with-apxs=/opt/local/bin/apxs
mkdir build
cp libtool build/
make
cp ./apache-2.0/mod_jk.so /opt/local/lib/httpd/

Friday, January 15, 2016

tomcat sloooow to start, smartos, kvm: urandom?

A fresh installation of CentOS 7 in a SmartOS KVM virtual machine using a dataset (     image_uuid: d8e65ea2-1f3e-11e5-8557-6b43e0a88b38).
CentOS updated just after the installation.


  • apache-tomcat-7.0.64
  • Java(TM) SE Runtime Environment (build 1.7.0_80-b15)


I noticed that Tomcat, at startup was very very very, help me, very slow to start.
I used strace to look at what was happening (even if I don't understand anything).

I got a lot of

[pid  1279] futex(0x7f5a880a7154, FUTEX_WAIT_BITSET_PRIVATE, 1, {348, 455527976}, ffffffff) = -1 ETIMEDOUT (Connection timed out)
[pid  1279] futex(0x7f5a880a7128, FUTEX_WAKE_PRIVATE, 1) = 0


Just googled around. I found something similar.

So the solution is: to add the following option to java in the tomcat startup script

-Djava.security.egd=file:/dev/urandom

 (like CATALINA_OPTS="$CATALINA_OPTS -Djava.security.egd=file:/dev/./urandom").

Who knows?

Wednesday, September 23, 2015

elasticsearch, reindex using logstash

Well, I'm not an elasticsearch expert, not at all. And, as usual, my english sucks.

Let's say that you have indexed a bunch of stuff, and now you need to change an index type.
For instance, in my case, I've seen that a filed named "hostname" was splitted if it was containing a dash, like "tc-pi.pacs.mydomain" was splitted in two parts when creating graphs using kibana.
The solution, in order to avoid this hostname splitting, is to define "index" : "not_analyzed" in logstash mapping.

Well, reading around it is not possible to change mappings once the document were indexed.

So a solution, a workaround, thanks to this post is the following.

"Download" the old index

curl -XGET 'http://127.0.0.1:9200/dcmaudit/_mappings/'

Copy the result in a text editor for your convenience, then change the mapping, like

...
"hostname":{"type":"string", "index" : "not_analyzed"}
...

Create a new index:

curl -XPOST http://localhost:9200/dcmaudit2 -d '{"mappings":{"logs":{"properties":{"@timestamp":{"type":"date","format":"dateOptionalTime"},"@version":{"type":"string"},"ParticipantObjectIdentification2.ParticipantObjectTypeCode.displayName":{"type":"string", "index" : "not_analyzed"},"hostname":{"type":"string", "index" : "not_analyzed"},"message":{"type":"string"},"tags":{"type":"string"},"timestamp":{"type":"date","format":"dateOptionalTime"}}}}}'

Now let's create a logstash configuration file like this:

input {
  # We read from the "old" index
  elasticsearch {
    hosts => [ "localhost" ]
    port => "9200"
    index => "dcmaudit"
    size => 500
    scroll => "5m"
    docinfo => true
  }
}

filter {
  mutate {
    remove_field => [ "@timestamp", "@version" ]
  }
}

output {

elasticsearch {
    host => "localhost"
    port => "9200"
    protocol => "http"
    index => "dcmaudit2"
    index_type => "%{[@metadata][_type]}"
    document_id => "%{[@metadata][_id]}"
  }

      stdout {
        codec => rubydebug
      }
}

Launch logstash

./bin/logstash -f conf.json

Now all the stuff from one index (dcmaudit) will be copied to the new one (dcmaudit2).

At this point you can delete the old index.

curl -XDELETE localhost:9200/dcmaudit

If you want, and if you need it, you can run this task again, recreating the old index name (dcmaudit) but whit the new mapping, and then repeat the logstash task changing the input and the output index accordingly.