~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-26 22:54:17 UTC
  • Revision ID: jill.rouleau@canonical.com-20150826225417-pjj90qtbfm8ll9g5
adding some logic for a nagios RO mysql user, fixed files path expected by charmhelper nrpe

Show diffs side-by-side

added added

removed removed

Lines of Context:
600
600
        check_cmd='check_procs -c 1:1 -C mysqld'
601
601
    )
602
602
    log('adding the script')
603
 
    rsync(os.path.join(os.getenv('CHARM_DIR'), 'files', 'check_mysql_conns.py'),
 
603
    rsync(os.path.join(os.getenv('CHARM_DIR'), 'files', 'nrpe-external-master', 'check_mysql_conns.py'),
604
604
          os.path.join(NAGIOS_PLUGINS, 'check_mysql_conns.py')),
605
605
    nrpe_setup.add_check(
606
606
        shortname='mysql_conns',
608
608
        check_cmd='check_mysql_conns.py {}'.format(config('nagios-conn-check-params'))
609
609
    )
610
610
    nrpe_setup.write()
 
611
    import MySQLdb
 
612
    mypass = (config('root-password'))
 
613
    db = MySQLdb.connect(host='localhost', user='root', passwd=config('root-password'))
 
614
    c = db.cursor()
 
615
    c.execute("SELECT user FROM mysql.user WHERE user='nagios';")
 
616
    result = c.fetchone()
 
617
    if result is not None:
 
618
        return
 
619
    else:
 
620
        c.execute("CREATE USER 'nagios'@'localhost' IDENTIFIED BY %s;", (mypass))
 
621
        c.execute("GRANT SELECT ON mysql.* TO 'nagios'@'localhost';")
611
622
 
612
623
 
613
624
def main():