Keep Your Google Search Appliance Synced
There have been a lot of people asking how they can keep their GSA synced. Here is quick, simple, and easily configurable solution that should help. Set this up as a CRON job and you’re done.
Requires: PHP, cURL
<?php
/**
* @author Chris Williams ctwilliams[at]gmail[dot]com
* @version 0.0.1
* @example php gsa-sync.php
*/
define(‘GSA_PATH’, ‘http://gsa.xyz.com:8000′); // Replace ‘http://…’ with your gsa host and port
define(‘GSA_USERNAME’, ‘user’); // Replace ‘user’ with your username
define(‘GSA_PASSWORD’, ’secret’); // Replace ‘password’ with your password
/** Define DB collections */
$dbSources = array(‘dbcollection1′, ‘dbcollection2′);
/** Go to log in prompt */
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, GSA_PATH . ‘/EnterpriseController’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_COOKIEJAR, dirname(__FILE__).‘/cookie.txt’);
curl_exec($ch);
/** Authenticate */
curl_setopt($ch, CURLOPT_URL, GSA_PATH . ‘/EnterpriseController’);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,‘actionType=authenticateUser&userName=’ . GSA_USERNAME . ‘&password=’ . GSA_PASSWORD);
curl_exec($ch);
/** Loop through and trigger db sync for each collection in $dbSources */
if(is_array($dbSources)) {
foreach($dbSources as $source) {
curl_setopt($ch, CURLOPT_URL, GSA_PATH . ‘/EnterpriseController?actionType=syncDatabase&entryName=’ . $source);
curl_setopt($ch, CURLOPT_POST, false);
curl_exec($ch);
}
}
/** Close cURL connection */
curl_close($ch);
?>
Feedback and suggestions are appreciated… Enjoy!
