scripts/couchdb_check_replication
author Tomas Zeman <tzeman@volny.cz>
Fri, 30 Aug 2013 13:20:57 +0200
changeset 30 79eef9a447de
parent 10 5183f2628cd2
permissions -rwxr-xr-x
externalscripts/certificate_expiration-bsd: Certificate expiration check (BSD date(1) variant) as external check (via TCP)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     1
#!/usr/bin/env python
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     2
# -*- coding: latin1 -*-
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     3
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     4
"""
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     5
CouchDB replication status checker.
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     6
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     7
Checks output of curl _active_tasks and returns number of running replication tasks.
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     8
Invocation:
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     9
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    10
    curl -s -X GET http://localhost:5984/_active_tasks | ./check_replication
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    11
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    12
"""
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    13
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    14
import re
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    15
import simplejson as json
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    16
import sys
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    17
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    18
try:
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    19
    d = json.load(sys.stdin)
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    20
    cnt = 0
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    21
    for e in d:
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    22
        if e["type"] == "Replication" and re.search("Processed source update", e["status"]):
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    23
            cnt += 1
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    24
    print cnt
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    25
except Exception:
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    26
    print 0
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    27
5183f2628cd2 couchdb replication monitoring
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    28
# vim: et:ts=4:sw=4