Created
June 6, 2013 10:05
-
-
Save real34/5720523 to your computer and use it in GitHub Desktop.
CasperJs script to monitor MySQL replication slave status through PhpMyAdmin.
Tested with PhpMyAdmin v3.3.9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var casper = require('casper').create(); | |
var utils = require('utils'); | |
var phpMyAdminUrl = casper.cli.args[0]; | |
var phpMyAdminCredentials = { | |
pma_username: casper.cli.options.user, | |
pma_password: casper.cli.options.password | |
}; | |
if (!phpMyAdminUrl || !phpMyAdminCredentials.pma_username || !phpMyAdminCredentials.pma_password) { | |
casper.echo('Invalid parameters. Usage: casperjs monitor_slave.js http://example.com/phpMyAdmin --user=foo --password=bar'); | |
casper.exit(1); | |
} | |
casper.start(phpMyAdminUrl, function() { | |
this.fill('form[name="login_form"]', phpMyAdminCredentials, true); | |
}); | |
casper.then(function() { | |
var frameUrl = phpMyAdminUrl + this.evaluate(function getFrameUrl() { | |
return document.querySelector('#frame_content').getAttribute('src'); | |
}); | |
casper.thenOpen(frameUrl, function captureFrameContent() { | |
casper.click('a[href^="server_replication.php"]'); | |
}); | |
}); | |
casper.then(function() { | |
var getRelatedValueClassNameFromLabel = function(container, label) { | |
var nameElement = __utils__.getElementByXPath( | |
'.//td[@class="name" and starts-with(text(), "' + label + '")]/following-sibling::td[@class="value"]/span', | |
__utils__.findOne(container) | |
); | |
return nameElement.getAttribute('class'); | |
}; | |
this.test.assertEvalEquals( | |
getRelatedValueClassNameFromLabel, | |
'allfine', | |
'Slave_IO_Running is fine', | |
['#serverslavereplicationsummary', 'Slave_IO_Running'] | |
); | |
this.test.assertEvalEquals( | |
getRelatedValueClassNameFromLabel, | |
'allfine', | |
'Slave_SQL_Running is fine', | |
['#serverslavereplicationsummary', 'Slave_SQL_Running'] | |
); | |
}); | |
casper.run(function() { | |
this.test.renderResults(true, 0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment