Skip to content
Snippets Groups Projects
Commit bac6f77f authored by hahn's avatar hahn
Browse files

ci - add page checkssh

parent 659ef7a5
No related branches found
No related tags found
No related merge requests found
<?php
/* ######################################################################
IML DEPLOYMENT
webgui - check all ssh connections to puppet, git repos and taregt hosts
---------------------------------------------------------------------
2018-02-01 Axel <axel.hahn@iml.unibe.ch>
###################################################################### */
$sOK='<span class="ok">' . t('ok') . '</span>';
$sFAILED='<span class="error">' . t('error') . '</span>';
global $sOK;
global $sFAILED;
// test only
// $aConfig['mirrorPackages']=array('puppet' => array('target' => 'ladmin@calcium.iml.unibe.ch:/share/imldeployment'),);
/**
* exec a command and show OK or FAILED
*
* @global string $sOK
* @global string $sFAILED
* @param string $sCmd command to execute
* @return string
*/
function myExec($sCmd){
global $sOK, $sFAILED;
$sReturn='';
exec($sCmd . " 2>&1 && echo '$sOK' || echo '$sFAILED' ", $aOut);
$sReturn .= "<pre><strong>\$ $sCmd</strong><br>"
. implode('<br>', $aOut)."<br>"
. "</pre>";
return $sReturn;
}
$sOut = '<h2>SSH</h2>';
if(isset($aConfig['mirrorPackages']) && count($aConfig['mirrorPackages'])){
// test puppet
$sOut = '<h3>Puppet</h3>'
. '<ul>';
foreach ($aConfig['mirrorPackages'] as $sServer=>$aSettings) {
$sCmd = 'ssh ' . preg_replace('#\:\/.*#', '' , $aSettings['target']) . ' echo "hello from `hostname -f`"';
$sOut .= '<li><strong>' . $sServer . '</strong> ' . myExec($sCmd);
}
$sOut.='</ul>';
}
// ... then loop over all projects ...
$oPrj1 = new project();
foreach ($oPrj1->getProjects() as $sPrj) {
$oPrj = new project($sPrj);
$aPrjConfig = $oPrj->getConfig();
$sOut .= '<h3>' . $oPrj->getLabel() . '</h3>'
// . '<pre>'.print_r($aPrjConfig, 1).'</pre>'
. '<ul>';
// test repository
$sOut .= '<li>'.t('repositoryinfos').' <strong>' . $aPrjConfig['build']['url'] . '</strong> - '
. ($oPrj->getRepoRevision() ? $sOK : $sFAILED)
;
// loop over phases ...
foreach (array_keys($oPrj->getPhases()) as $sPhase) {
$sOut .= '<li>'.t('phase').' <strong>' . $sPhase . '</strong><ul>';
$sDeployhosts = array_key_exists("hosts", $aPrjConfig["phases"][$sPhase]) ? $aPrjConfig["phases"][$sPhase]["hosts"] : "";
if ($sDeployhosts) {
$sOut .= '<li>' . $sDeployhosts . '<br>';
$sCmd = 'ssh ' . $aConfig["installPackages"]["user"] . '@' . $sDeployhosts . ' echo "hello from `hostname -f`"';
$sOut.= myExec($sCmd);
}
$sOut.='</ul>';
}
$sOut.='</ul>';
}
echo $sOut;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment