~jillrouleau/charms/trusty/percona-cluster/add-nrpe-checks

« back to all changes in this revision

Viewing changes to hooks/percona_hooks.py

  • Committer: Jill Rouleau
  • Date: 2015-08-28 00:19:03 UTC
  • Revision ID: jill.rouleau@canonical.com-20150828001903-ntx7fi15hnlxgp6s
move mysql actions to utils, proper auth for check script

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
    notify_bootstrapped,
63
63
    is_bootstrapped,
64
64
    get_wsrep_value,
 
65
    configure_nagiosuser,
65
66
)
66
67
from charmhelpers.contrib.database.mysql import (
67
68
    PerconaClusterHelper,
605
606
    log('adding the script')
606
607
    rsync(os.path.join(os.getenv('CHARM_DIR'), 'files', 'nrpe-external-master', 'check_mysql_conns.py'),
607
608
          os.path.join(NAGIOS_PLUGINS, 'check_mysql_conns.py')),
 
609
    os.chmod((os.path.join(NAGIOS_PLUGINS, 'check_mysql_conns.py')), 0775)
608
610
    nrpe_setup.add_check(
609
611
        shortname='mysql_conns',
610
612
        description='What percentage of max_conns MySQL is using',
611
613
        check_cmd='check_mysql_conns.py {}'.format(config('nagios-conn-check-params'))
612
614
    )
613
615
    nrpe_setup.write()
614
 
    import MySQLdb
615
 
    mypass = (config('root-password'))
616
 
    db = MySQLdb.connect(host='localhost', user='root', passwd=config('root-password'))
617
 
    c = db.cursor()
618
 
    c.execute("SELECT user FROM mysql.user WHERE user='nagios';")
619
 
    result = c.fetchone()
620
 
    if result is not None:
621
 
        return
622
 
    else:
623
 
        c.execute("CREATE USER 'nagios'@'localhost' IDENTIFIED BY %s;", (mypass))
624
 
        c.execute("GRANT SELECT ON mysql.* TO 'nagios'@'localhost';")
 
616
    # TODO: really what ought to happen here is a check for the config val and generate a pw on empty
 
617
    configure_nagiosuser(config('nagios-password'))
 
618
    NAGIOS_CREDS = os.path.join(NAGIOS_PLUGINS, "nagios.mysql")
 
619
    f = open(NAGIOS_CREDS, 'w')
 
620
    f.write(config('nagios-password'))
 
621
    f.close()
625
622
 
626
623
 
627
624
def main():