svnno****@sourc*****
svnno****@sourc*****
2010年 1月 13日 (水) 10:49:39 JST
Revision: 88 http://sourceforge.jp/projects/ngms/svn/view?view=rev&revision=88 Author: takayah Date: 2010-01-13 10:49:39 +0900 (Wed, 13 Jan 2010) Log Message: ----------- [NMAutoConf] rename calss name Added Paths: ----------- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/NMAutoConfFacade.scala trunk/source/NMAutoConf/src/info/ngms/nmautoconf/NMAutoConfParameter.scala trunk/source/NMAutoConf/src/info/ngms/nmautoconf/NMAutoConfResult.scala trunk/source/NMAutoConf/src/info/ngms/nmautoconf/NMAutoConfType.scala trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/NMCactiAutoConf.scala trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/NMCactiAutoConfParameter.scala trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/NMCactiAutoConfResult.scala trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NMNagiosAutoConf.scala trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NMNagiosAutoConfParameter.scala trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NMNagiosAutoConfResult.scala trunk/source/NMAutoConf/test/info/ trunk/source/NMAutoConf/test/info/ngms/ trunk/source/NMAutoConf/test/info/ngms/nmautoconf/ trunk/source/NMAutoConf/test/info/ngms/nmautoconf/NMAutoConfFacadeTest.scala Removed Paths: ------------- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/AutoConfFacade.scala trunk/source/NMAutoConf/src/info/ngms/nmautoconf/AutoConfParameter.scala trunk/source/NMAutoConf/src/info/ngms/nmautoconf/AutoConfResult.scala trunk/source/NMAutoConf/src/info/ngms/nmautoconf/AutoConfType.scala trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/CactiAutoConf.scala trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/CactiAutoConfParameter.scala trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/CactiAutoConfResult.scala trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NagiosAutoConf.scala trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NagiosAutoConfParameter.scala trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NagiosAutoConfResult.scala trunk/source/NMNetWalker/test/info/ngms/nmnetwalker/AutoConfFacadeTest.scala Deleted: trunk/source/NMAutoConf/src/info/ngms/nmautoconf/AutoConfFacade.scala =================================================================== --- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/AutoConfFacade.scala 2010-01-13 01:11:29 UTC (rev 87) +++ trunk/source/NMAutoConf/src/info/ngms/nmautoconf/AutoConfFacade.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -1,32 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmautoconf - -import info.ngms.nmautoconf.nagios.NagiosAutoConf -import info.ngms.nmautoconf.nagios.NagiosAutoConfParameter -import info.ngms.nmautoconf.cacti.CactiAutoConf -import info.ngms.nmautoconf.cacti.CactiAutoConfParameter - -/** - * 自動設定結果を取得するクラス - * @version $Id$ - * @author - */ -private[nmautoconf] object AutoConfFacade { - import info.ngms.nmtree.NMTree.TDescriptionElement - - def getResult(autoConfType: AutoConfType, params: Map[String, String]): AutoConfResult = { - autoConfType match { - case NagiosAutoConfType => - val param = NagiosAutoConfParameter.fromMap(params) - NagiosAutoConf.createResult(param) - case CactiAutoConfType => - val param = CactiAutoConfParameter.fromMap(params) - CactiAutoConf.createResult(param) - case _ => throw new IllegalArgumentException("invalid AutoConfType") - } - } -} - Deleted: trunk/source/NMAutoConf/src/info/ngms/nmautoconf/AutoConfParameter.scala =================================================================== --- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/AutoConfParameter.scala 2010-01-13 01:11:29 UTC (rev 87) +++ trunk/source/NMAutoConf/src/info/ngms/nmautoconf/AutoConfParameter.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -1,20 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmautoconf - -/** - * 情報を設定するのに必要なパラメータークラス - * - * @version $Id$ - * @author - */ -private[nmautoconf] trait AutoConfParameter { - import java.net.InetAddress - - val dir: String - val address: InetAddress - val hostname: String -} - Deleted: trunk/source/NMAutoConf/src/info/ngms/nmautoconf/AutoConfResult.scala =================================================================== --- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/AutoConfResult.scala 2010-01-13 01:11:29 UTC (rev 87) +++ trunk/source/NMAutoConf/src/info/ngms/nmautoconf/AutoConfResult.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -1,19 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmautoconf - -/** - * 自動設定を行うクラス - * - * @version $Id$ - * @author - */ -private[nmautoconf] abstract class AutoConfResult { - import info.ngms.nmtree.NMDescriptions - - def toNMDescriptions(): NMDescriptions - def commit(): Unit -} - Deleted: trunk/source/NMAutoConf/src/info/ngms/nmautoconf/AutoConfType.scala =================================================================== --- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/AutoConfType.scala 2010-01-13 01:11:29 UTC (rev 87) +++ trunk/source/NMAutoConf/src/info/ngms/nmautoconf/AutoConfType.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -1,15 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmautoconf - -/** - * AutoConf のタイプを表す Enumeration クラス - * @version $Id$ - * @author - */ -abstract class AutoConfType -case object NagiosAutoConfType extends AutoConfType -case object CactiAutoConfType extends AutoConfType - Copied: trunk/source/NMAutoConf/src/info/ngms/nmautoconf/NMAutoConfFacade.scala (from rev 86, trunk/source/NMAutoConf/src/info/ngms/nmautoconf/AutoConfFacade.scala) =================================================================== --- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/NMAutoConfFacade.scala (rev 0) +++ trunk/source/NMAutoConf/src/info/ngms/nmautoconf/NMAutoConfFacade.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -0,0 +1,32 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmautoconf + +import info.ngms.nmautoconf.cacti.NMCactiAutoConf +import info.ngms.nmautoconf.cacti.NMCactiAutoConfParameter +import info.ngms.nmautoconf.nagios.NMNagiosAutoConf +import info.ngms.nmautoconf.nagios.NMNagiosAutoConfParameter + +/** + * 自動設定結果を取得するクラス + * @version $Id$ + * @author + */ +private[nmautoconf] object NMAutoConfFacade { + import info.ngms.nmtree.NMTree.TDescriptionElement + + def getResult(autoConfType: NMAutoConfType, params: Map[String, String]): NMAutoConfResult = { + autoConfType match { + case NMNagiosAutoConfType => + val param = NMNagiosAutoConfParameter.fromMap(params) + NMNagiosAutoConf.createResult(param) + case NMCactiAutoConfType => + val param = NMCactiAutoConfParameter.fromMap(params) + NMCactiAutoConf.createResult(param) + case _ => throw new IllegalArgumentException("invalid NMAutoConfType") + } + } +} + Copied: trunk/source/NMAutoConf/src/info/ngms/nmautoconf/NMAutoConfParameter.scala (from rev 86, trunk/source/NMAutoConf/src/info/ngms/nmautoconf/AutoConfParameter.scala) =================================================================== --- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/NMAutoConfParameter.scala (rev 0) +++ trunk/source/NMAutoConf/src/info/ngms/nmautoconf/NMAutoConfParameter.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -0,0 +1,20 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmautoconf + +/** + * 情報を設定するのに必要なパラメータークラス + * + * @version $Id$ + * @author + */ +private[nmautoconf] trait NMAutoConfParameter { + import java.net.InetAddress + + val dir: String + val address: InetAddress + val hostname: String +} + Copied: trunk/source/NMAutoConf/src/info/ngms/nmautoconf/NMAutoConfResult.scala (from rev 86, trunk/source/NMAutoConf/src/info/ngms/nmautoconf/AutoConfResult.scala) =================================================================== --- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/NMAutoConfResult.scala (rev 0) +++ trunk/source/NMAutoConf/src/info/ngms/nmautoconf/NMAutoConfResult.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -0,0 +1,19 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmautoconf + +/** + * 自動設定を行うクラス + * + * @version $Id$ + * @author + */ +private[nmautoconf] abstract class NMAutoConfResult { + import info.ngms.nmtree.NMDescriptions + + def toNMDescriptions(): NMDescriptions + def commit(): Unit +} + Copied: trunk/source/NMAutoConf/src/info/ngms/nmautoconf/NMAutoConfType.scala (from rev 86, trunk/source/NMAutoConf/src/info/ngms/nmautoconf/AutoConfType.scala) =================================================================== --- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/NMAutoConfType.scala (rev 0) +++ trunk/source/NMAutoConf/src/info/ngms/nmautoconf/NMAutoConfType.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -0,0 +1,15 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmautoconf + +/** + * AutoConf のタイプを表す Enumeration クラス + * @version $Id$ + * @author + */ +abstract class NMAutoConfType +case object NMNagiosAutoConfType extends NMAutoConfType +case object NMCactiAutoConfType extends NMAutoConfType + Deleted: trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/CactiAutoConf.scala =================================================================== --- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/CactiAutoConf.scala 2010-01-13 01:11:29 UTC (rev 87) +++ trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/CactiAutoConf.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -1,22 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmautoconf.cacti - -import info.ngms.nmtree.NMTree.TDescriptionElement - -import info.ngms.nmautoconf.AutoConfResult - -/** - * Cacti の設定ファイルを生成させるクラス - * - * @version $Id$ - * @author - */ -private[nmautoconf] object CactiAutoConf { - def createResult(param: CactiAutoConfParameter): AutoConfResult = { - new CactiAutoConfResult(param.dir, param.address, param.hostname) - } -} - Deleted: trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/CactiAutoConfParameter.scala =================================================================== --- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/CactiAutoConfParameter.scala 2010-01-13 01:11:29 UTC (rev 87) +++ trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/CactiAutoConfParameter.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -1,47 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmautoconf.cacti - -import java.net.InetAddress - -/** - * Cacti の設定に必要なパラメーターを生成するオブジェクト - * - * @version $Id$ - * @author - */ -private[nmautoconf] object CactiAutoConfParameter { - // param key - val DIR: String = "dir" - val ADDRESS: String = "address" - val HOSTNAME: String = "hostname" - - def fromMap(params: Map[String, String]): CactiAutoConfParameter = { - val dirStr = params(DIR) - require((dirStr != null) && (dirStr.length() >= 1), "dir is null") - val dir = dirStr - - val addressStr = params(ADDRESS) - require((addressStr != null) && (addressStr.length() >= 1), "address is null") - val address = InetAddress.getByName(addressStr) - - val hostnameStr = params(HOSTNAME) - require((hostnameStr != null) && (hostnameStr.length() >= 1), "hostname is null") - val hostname = hostnameStr - - new CactiAutoConfParameter(dir, address, hostname) - } -} - -/** - * Cacti の設定に必要なパラメーターを生成するオブジェクト - * - * @version $Id$ - * @author - */ -private[nmautoconf] class CactiAutoConfParameter(val dir: String, - val address: InetAddress, - val hostname: String) extends AutoConfParameter - Deleted: trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/CactiAutoConfResult.scala =================================================================== --- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/CactiAutoConfResult.scala 2010-01-13 01:11:29 UTC (rev 87) +++ trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/CactiAutoConfResult.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -1,90 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmautoconf.cacti - -import java.net.InetAddress - -import info.ngms.nmautoconf.AutoConfResult -import info.ngms.nmautoconf.util.ExecCmd - -/** - * Cacti の設定を反映させるクラス - * - * @version $Id$ - * @author - */ -private[nmautoconf] class CactiAutoConfResult(dir: String, - address: InetAddress, - hostname: String) extends AutoConfResult { - import info.ngms.nmtree.NMDescription - import info.ngms.nmtree.NMDescriptions - - val DIR: String = "dir" - val HOSTNAME: String = "hostname" - val ADDRESS: String = "address" - - override def toNMDescriptions(): NMDescriptions = { - val descriptions = new NMDescriptions - val dirDesc = NMDescription.make(DIR, dir) - descriptions.header += (DIR -> dirDesc) - val hostnameDesc = NMDescription.make(HOSTNAME, hostname) - descriptions.header += (HOSTNAME -> hostnameDesc) - val addressDesc = NMDescription.make(ADDRESS, address.getHostAddress()) - descriptions.header += (ADDRESS -> addressDesc) - - descriptions - } - - override def commit(): Unit = { - addDevice() - val hostid = getHostID() - if (hostid == "") { // addDevice fail? - // FIXME - // 何の Exception を throw するかを再考する必要がある。 - throw new RuntimeException("hostid not found\n") - } else { - addGraph(hostid) - } - } - - // php add_device.php --description=hostname --ip=address --template=1 \ - // --avail=snmp --version=2 --community=public - // - // host-template: Generic SNMP-enabled Host - private def addDevice() = { - val cmd = - "php %s/cli/add_device.php --description=%s --ip=%s ".format(dir, hostname, address.getHostAddress()) + - "--quiet --template=1 --avail=snmp --version=2 --community=public" - val proc = new ExecCmd(cmd) - proc.exec - } - - private def getHostID() = { - val cmd = "php %s/cli/add_graphs.php --list-hosts".format(dir) - val proc = new ExecCmd(cmd) - val result = proc.exec - val lines = result.split("\\n").filter(_.contains(address.getHostAddress())).toList - if (lines.isEmpty) { - "" - } else { - lines.head.split("\\s+").toList.head - } - } - - //php add_graphs.php --graph-type=ds --graph-template-id=2 --host-id=?? \ - // --snmp-query-id=1 --snmp-query-type-id=13 \ - // --snmp-field=ifOperStatus --snmp-value=Up - // graph-template-id: Interface - Traffic (bits/sec) - // snmp-query-id: SNMP - Interface Statistics - // snmp-query-type-id: In/Out Bits - private def addGraph(hostid: String) = { - val cmd = "php %s/cli/add_graphs.php ".format(dir) + - "--graph-type=ds --graph-template-id=2 --host-id=%s ".format(hostid) + - "--quiet --snmp-query-id=1 --snmp-query-type-id=13 --snmp-field=ifOperStatus --snmp-value=Up" - val proc = new ExecCmd(cmd) - proc.exec - } -} - Copied: trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/NMCactiAutoConf.scala (from rev 86, trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/CactiAutoConf.scala) =================================================================== --- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/NMCactiAutoConf.scala (rev 0) +++ trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/NMCactiAutoConf.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -0,0 +1,22 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmautoconf.cacti + +import info.ngms.nmtree.NMTree.TDescriptionElement + +import info.ngms.nmautoconf.NMAutoConfResult + +/** + * Cacti の設定ファイルを生成させるクラス + * + * @version $Id$ + * @author + */ +private[nmautoconf] object NMCactiAutoConf { + def createResult(param: NMCactiAutoConfParameter): NMAutoConfResult = { + new NMCactiAutoConfResult(param.dir, param.address, param.hostname) + } +} + Copied: trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/NMCactiAutoConfParameter.scala (from rev 86, trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/CactiAutoConfParameter.scala) =================================================================== --- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/NMCactiAutoConfParameter.scala (rev 0) +++ trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/NMCactiAutoConfParameter.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -0,0 +1,47 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmautoconf.cacti + +import java.net.InetAddress + +/** + * Cacti の設定に必要なパラメーターを生成するオブジェクト + * + * @version $Id$ + * @author + */ +private[nmautoconf] object NMCactiAutoConfParameter { + // param key + val DIR: String = "dir" + val ADDRESS: String = "address" + val HOSTNAME: String = "hostname" + + def fromMap(params: Map[String, String]): NMCactiAutoConfParameter = { + val dirStr = params(DIR) + require((dirStr != null) && (dirStr.length() >= 1), "dir is null") + val dir = dirStr + + val addressStr = params(ADDRESS) + require((addressStr != null) && (addressStr.length() >= 1), "address is null") + val address = InetAddress.getByName(addressStr) + + val hostnameStr = params(HOSTNAME) + require((hostnameStr != null) && (hostnameStr.length() >= 1), "hostname is null") + val hostname = hostnameStr + + new NMCactiAutoConfParameter(dir, address, hostname) + } +} + +/** + * Cacti の設定に必要なパラメーターを生成するオブジェクト + * + * @version $Id$ + * @author + */ +private[nmautoconf] class NMCactiAutoConfParameter(val dir: String, + val address: InetAddress, + val hostname: String) extends NMAutoConfParameter + Copied: trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/NMCactiAutoConfResult.scala (from rev 86, trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/CactiAutoConfResult.scala) =================================================================== --- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/NMCactiAutoConfResult.scala (rev 0) +++ trunk/source/NMAutoConf/src/info/ngms/nmautoconf/cacti/NMCactiAutoConfResult.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -0,0 +1,90 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmautoconf.cacti + +import java.net.InetAddress + +import info.ngms.nmautoconf.NMAutoConfResult +import info.ngms.nmautoconf.util.ExecCmd + +/** + * Cacti の設定を反映させるクラス + * + * @version $Id$ + * @author + */ +private[nmautoconf] class NMCactiAutoConfResult(dir: String, + address: InetAddress, + hostname: String) extends NMAutoConfResult { + import info.ngms.nmtree.NMDescription + import info.ngms.nmtree.NMDescriptions + + val DIR: String = "dir" + val HOSTNAME: String = "hostname" + val ADDRESS: String = "address" + + override def toNMDescriptions(): NMDescriptions = { + val descriptions = new NMDescriptions + val dirDesc = NMDescription.make(DIR, dir) + descriptions.header += (DIR -> dirDesc) + val hostnameDesc = NMDescription.make(HOSTNAME, hostname) + descriptions.header += (HOSTNAME -> hostnameDesc) + val addressDesc = NMDescription.make(ADDRESS, address.getHostAddress()) + descriptions.header += (ADDRESS -> addressDesc) + + descriptions + } + + override def commit(): Unit = { + addDevice() + val hostid = getHostID() + if (hostid == "") { // addDevice fail? + // FIXME + // 何の Exception を throw するかを再考する必要がある。 + throw new RuntimeException("hostid not found\n") + } else { + addGraph(hostid) + } + } + + // php add_device.php --description=hostname --ip=address --template=1 \ + // --avail=snmp --version=2 --community=public + // + // host-template: Generic SNMP-enabled Host + private def addDevice() = { + val cmd = + "php %s/cli/add_device.php --description=%s --ip=%s ".format(dir, hostname, address.getHostAddress()) + + "--quiet --template=1 --avail=snmp --version=2 --community=public" + val proc = new ExecCmd(cmd) + proc.exec + } + + private def getHostID() = { + val cmd = "php %s/cli/add_graphs.php --list-hosts".format(dir) + val proc = new ExecCmd(cmd) + val result = proc.exec + val lines = result.split("\\n").filter(_.contains(address.getHostAddress())).toList + if (lines.isEmpty) { + "" + } else { + lines.head.split("\\s+").toList.head + } + } + + //php add_graphs.php --graph-type=ds --graph-template-id=2 --host-id=?? \ + // --snmp-query-id=1 --snmp-query-type-id=13 \ + // --snmp-field=ifOperStatus --snmp-value=Up + // graph-template-id: Interface - Traffic (bits/sec) + // snmp-query-id: SNMP - Interface Statistics + // snmp-query-type-id: In/Out Bits + private def addGraph(hostid: String) = { + val cmd = "php %s/cli/add_graphs.php ".format(dir) + + "--graph-type=ds --graph-template-id=2 --host-id=%s ".format(hostid) + + "--quiet --snmp-query-id=1 --snmp-query-type-id=13 --snmp-field=ifOperStatus --snmp-value=Up" + val proc = new ExecCmd(cmd) + proc.exec + } +} + Copied: trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NMNagiosAutoConf.scala (from rev 86, trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NagiosAutoConf.scala) =================================================================== --- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NMNagiosAutoConf.scala (rev 0) +++ trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NMNagiosAutoConf.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -0,0 +1,38 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmautoconf.nagios + +import info.ngms.nmtree.NMTree.TDescriptionElement + +import info.ngms.nmautoconf.NMAutoConfResult + +/** + * Nagio の設定ファイルを生成させるクラス + * + * @version $Id$ + * @author + */ +private[nmautoconf] object NMNagiosAutoConf { + def createResult(param: NMNagiosAutoConfParameter): NMAutoConfResult = { + // FIXME + // 将来的にテンプレートは NMTree から読み出すようにする。 + val fmt = """define host { + use NGMS_host + host_name %s + alias %s + address %s +} + +define service { + use NGMS_service_ping + host_name %s +} +""" + val conf = fmt.format(fmt, param.hostname, param.hostname, param.address.getHostAddress(), param.hostname) + + new NMNagiosAutoConfResult(param.dir, param.hostname, conf) + } +} + Copied: trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NMNagiosAutoConfParameter.scala (from rev 86, trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NagiosAutoConfParameter.scala) =================================================================== --- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NMNagiosAutoConfParameter.scala (rev 0) +++ trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NMNagiosAutoConfParameter.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -0,0 +1,47 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmautoconf.nagios + +import java.net.InetAddress + +/** + * Nagios の設定に必要なパラメーターを生成するオブジェクト + * + * @version $Id$ + * @author + */ +private[nmautoconf] object NMNagiosAutoConfParameter { + // param key + val DIR: String = "dir" + val ADDRESS: String = "address" + val HOSTNAME: String = "hostname" + + def fromMap(params: Map[String, String]): NMNagiosAutoConfParameter = { + val dirStr = params(DIR) + require((dirStr != null) && (dirStr.length() >= 1), "dir is null") + val dir = dirStr + + val addressStr = params(ADDRESS) + require((addressStr != null) && (addressStr.length() >= 1), "address is null") + val address = InetAddress.getByName(addressStr) + + val hostnameStr = params(HOSTNAME) + require((hostnameStr != null) && (hostnameStr.length() >= 1), "hostname is null") + val hostname = hostnameStr + + new NMNagiosAutoConfParameter(dir, address, hostname) + } +} + +/** + * Nagios の設定に必要なパラメーターを生成するオブジェクト + * + * @version $Id$ + * @author + */ +private[nmautoconf] class NMNagiosAutoConfParameter(val dir: String, + val address: InetAddress, + val hostname: String) extends NMAutoConfParameter + Copied: trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NMNagiosAutoConfResult.scala (from rev 86, trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NagiosAutoConfResult.scala) =================================================================== --- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NMNagiosAutoConfResult.scala (rev 0) +++ trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NMNagiosAutoConfResult.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -0,0 +1,55 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmautoconf.nagios + +import info.ngms.nmautoconf.NMAutoConfResult +import info.ngms.nmautoconf.util.ExecCmd + +/** + * Nagio の設定を反映させるクラス + * + * @version $Id$ + * @author + */ +private[nmautoconf] class NMNagiosAutoConfResult(dir: String, + hostname: String, + config: String) extends NMAutoConfResult { + import scala.io.Source + + import info.ngms.nmtree.NMDescription + import info.ngms.nmtree.NMDescriptions + + val DIR: String = "dir" + val HOSTNAME: String = "hostname" + val CONFIG: String = "config" + + override def toNMDescriptions(): NMDescriptions = { + val descriptions = new NMDescriptions + val dirDesc = NMDescription.make(DIR, dir) + descriptions.header += (DIR -> dirDesc) + val hostnameDesc = NMDescription.make(HOSTNAME, hostname) + descriptions.header += (HOSTNAME -> hostnameDesc) + val configDesc = NMDescription.make(CONFIG, config) + descriptions.header += (CONFIG -> configDesc) + + descriptions + } + + override def commit(): Unit = { + // FIXME + val filename = "%s/etc/NGMS/%s.cfg".format(dir, hostname) + val file = new java.io.FileWriter(filename) + file.write(config) + file.close + + val lockFile = "%s/var/nagios.lock".format(dir) + val pid = Source.fromFile(lockFile).getLines.mkString.trim + val cmd = "kill -1 %s".format(pid) + printf("send HUP signal to Nagios: %s\n",cmd) + val proc = new ExecCmd(cmd) + proc.exec + } +} + Deleted: trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NagiosAutoConf.scala =================================================================== --- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NagiosAutoConf.scala 2010-01-13 01:11:29 UTC (rev 87) +++ trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NagiosAutoConf.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -1,38 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmautoconf.nagios - -import info.ngms.nmtree.NMTree.TDescriptionElement - -import info.ngms.nmautoconf.AutoConfResult - -/** - * Nagio の設定ファイルを生成させるクラス - * - * @version $Id$ - * @author - */ -private[nmautoconf] object NagiosAutoConf { - def createResult(param: NagiosAutoConfParameter): AutoConfResult = { - // FIXME - // 将来的にテンプレートは NMTree から読み出すようにする。 - val fmt = """define host { - use NGMS_host - host_name %s - alias %s - address %s -} - -define service { - use NGMS_service_ping - host_name %s -} -""" - val conf = fmt.format(fmt, param.hostname, param.hostname, param.address.getHostAddress(), param.hostname) - - new NagiosAutoConfResult(param.dir, param.hostname, conf) - } -} - Deleted: trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NagiosAutoConfParameter.scala =================================================================== --- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NagiosAutoConfParameter.scala 2010-01-13 01:11:29 UTC (rev 87) +++ trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NagiosAutoConfParameter.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -1,47 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmautoconf.nagios - -import java.net.InetAddress - -/** - * Nagios の設定に必要なパラメーターを生成するオブジェクト - * - * @version $Id$ - * @author - */ -private[nmautoconf] object NagiosAutoConfParameter { - // param key - val DIR: String = "dir" - val ADDRESS: String = "address" - val HOSTNAME: String = "hostname" - - def fromMap(params: Map[String, String]): NagiosAutoConfParameter = { - val dirStr = params(DIR) - require((dirStr != null) && (dirStr.length() >= 1), "dir is null") - val dir = dirStr - - val addressStr = params(ADDRESS) - require((addressStr != null) && (addressStr.length() >= 1), "address is null") - val address = InetAddress.getByName(addressStr) - - val hostnameStr = params(HOSTNAME) - require((hostnameStr != null) && (hostnameStr.length() >= 1), "hostname is null") - val hostname = hostnameStr - - new NagiosAutoConfParameter(dir, address, hostname) - } -} - -/** - * Nagios の設定に必要なパラメーターを生成するオブジェクト - * - * @version $Id$ - * @author - */ -private[nmautoconf] class NagiosAutoConfParameter(val dir: String, - val address: InetAddress, - val hostname: String) extends AutoConfParameter - Deleted: trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NagiosAutoConfResult.scala =================================================================== --- trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NagiosAutoConfResult.scala 2010-01-13 01:11:29 UTC (rev 87) +++ trunk/source/NMAutoConf/src/info/ngms/nmautoconf/nagios/NagiosAutoConfResult.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -1,55 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmautoconf.nagios - -import info.ngms.nmautoconf.AutoConfResult -import info.ngms.nmautoconf.util.ExecCmd - -/** - * Nagio の設定を反映させるクラス - * - * @version $Id$ - * @author - */ -private[nmautoconf] class NagiosAutoConfResult(dir: String, - hostname: String, - config: String) extends AutoConfResult { - import scala.io.Source - - import info.ngms.nmtree.NMDescription - import info.ngms.nmtree.NMDescriptions - - val DIR: String = "dir" - val HOSTNAME: String = "hostname" - val CONFIG: String = "config" - - override def toNMDescriptions(): NMDescriptions = { - val descriptions = new NMDescriptions - val dirDesc = NMDescription.make(DIR, dir) - descriptions.header += (DIR -> dirDesc) - val hostnameDesc = NMDescription.make(HOSTNAME, hostname) - descriptions.header += (HOSTNAME -> hostnameDesc) - val configDesc = NMDescription.make(CONFIG, config) - descriptions.header += (CONFIG -> configDesc) - - descriptions - } - - override def commit(): Unit = { - // FIXME - val filename = "%s/etc/NGMS/%s.cfg".format(dir, hostname) - val file = new java.io.FileWriter(filename) - file.write(config) - file.close - - val lockFile = "%s/var/nagios.lock".format(dir) - val pid = Source.fromFile(lockFile).getLines.mkString.trim - val cmd = "kill -1 %s".format(pid) - printf("send HUP signal to Nagios: %s\n",cmd) - val proc = new ExecCmd(cmd) - proc.exec - } -} - Copied: trunk/source/NMAutoConf/test/info/ngms/nmautoconf/NMAutoConfFacadeTest.scala (from rev 85, trunk/source/NMNetWalker/test/info/ngms/nmnetwalker/AutoConfFacadeTest.scala) =================================================================== --- trunk/source/NMAutoConf/test/info/ngms/nmautoconf/NMAutoConfFacadeTest.scala (rev 0) +++ trunk/source/NMAutoConf/test/info/ngms/nmautoconf/NMAutoConfFacadeTest.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -0,0 +1,32 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmautoconf + +/** + * NMAutoConfFacade のテストクラス + * + * @version $Id$ + * @author + */ +object NMAutoConfFacadeTest { + import info.ngms.nmtree.NMFileSystemTree + import info.ngms.nmtree.NMPath + import info.ngms.nmtree.NMTree + + def main(args : Array[String]) : Unit = { + val path = new NMPath("/") + + val fs = new NMFileSystemTree("/tmp", path) + NMTree.mount(path, fs) + + val params = Map("dir" -> "/usr/local/nagios", + "address" -> "192.168.1.1", + "hostname" -> "myname") + + val autoConfResult = NMAutoConfFacade.getResult(NMNagiosAutoConfType, params) + autoConfResult.commit + } +} + Deleted: trunk/source/NMNetWalker/test/info/ngms/nmnetwalker/AutoConfFacadeTest.scala =================================================================== --- trunk/source/NMNetWalker/test/info/ngms/nmnetwalker/AutoConfFacadeTest.scala 2010-01-13 01:11:29 UTC (rev 87) +++ trunk/source/NMNetWalker/test/info/ngms/nmnetwalker/AutoConfFacadeTest.scala 2010-01-13 01:49:39 UTC (rev 88) @@ -1,32 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmnetwalker - -/** - * AutoConfFacade のテストクラス - * - * @version $Id$ - * @author - */ -object AutoConfFacadeTest { - import info.ngms.nmtree.NMFileSystemTree - import info.ngms.nmtree.NMPath - import info.ngms.nmtree.NMTree - - def main(args : Array[String]) : Unit = { - val path = new NMPath("/") - - val fs = new NMFileSystemTree("/tmp", path) - NMTree.mount(path, fs) - - val params = Map("dir" -> "/usr/local/nagios", - "address" -> "192.168.1.1", - "hostname" -> "myname") - - val autoConfResult = AutoConfFacade.getResult(NagiosAutoConfType, params) - autoConfResult.commit - } -} -