1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
<?php
# $Id: importer.php,v 1.8 2002/07/01 06:57:48 kemuri Exp $
/*
* Copyright (c) 2002 Ypsilon.Net AG, Germany
*
* This file is part of Nagat.
*
* Nagat is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Nagat is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Nagat; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
# Page variables
define("PAGE_ID","importer");
define("PAGE_TITLE","Importer");
require_once("local.inc");
include_once(NGT_LIB."head.inc");
if( !isset($action) ) $action = "";
if( !is_array($files) ) $files = array();
$totalcount = 0;
# Try to get the nagios.cfg from previous import
$nagioscfg = PluginGetConfig("nagioscfg");
if( $action == "importobjects" ) {
print "<p>Importing objects:</p>\n";
foreach( $files as $filename ) {
print "<li> Reading file $filename.. ";
flush();
$count = PluginImportObjects($filename);
if( $count == 0 ) {
print "no objects found?";
} else if ($count == -1 ) {
print "error reading file";
} else {
print "read $count.";
$totalcount += $count;
}
print "<br>\n";
flush();
}
print "<p>Read $totalcount objects in total</p>\n";
exit();
} else if( $action == "importcfg" && count($files) > 0 ) {
print "<p>Importing configuration files:</p>\n";
foreach( $files as $fileid ) {
$filename = NAGIOS_ETC.$NAGIOS_CFGFILES[$fileid];
print "<li> Processing file : $filename.. ";
flush();
if( $result = PluginImportCfgFile($fileid) ) {
print "failed : ".$result;
} else {
print "ok!";
$totalcount++;
}
flush();
}
print "<p>Read $totalcount configuration files.</p>\n";
exit();
}
?>
<p>
<form action="importer.php" method="POST">
<input type="hidden" name="action" value="importcfg">
</p>
<p>
No nagios.cfg data found. <br>
<br>
<?
foreach($NAGIOS_CFGFILES as $key => $filename) {
$fullloc = NAGIOS_ETC.$filename;
print <<<HTML
<input type="checkbox" name="files[]" value="$key"> $fullloc<br>
HTML;
}
?>
<br>
<input type="submit" value="Start importing configuration files">
</p>
</form>
<?
if( $nagioscfg != NULL && is_array($nagioscfg['cfg_file']) ) {
?>
<p>
<form action="importer.php" method="POST">
<input type="hidden" name="action" value="importobjects">
</p>
<p>
Please select the files you want to import:<br>
</p>
<?
foreach($nagioscfg['cfg_file'] as $filename) {
print <<<HTML
<input type="checkbox" name="files[]" value="$filename"> $filename<br>
HTML;
}
?>
<br>
<input type="submit" value="Start importing objects">
</form>
<br>
<b><u>DevNote:</u></b>
The importer will not clear the configuration currently loaded.<br>
You might end up with doubles when importing twice. This behaviour will
change<br> in the future.
<br>
<?
}
include_once(NGT_LIB."tail.inc");
?>
|