Imported Upstream version 2.6.2
This commit is contained in:
parent
a367d9bc54
commit
45043b58d0
246 changed files with 18228 additions and 1415 deletions
30
scripts/java/jNutList/README
Normal file
30
scripts/java/jNutList/README
Normal file
|
@ -0,0 +1,30 @@
|
|||
jNutList example application
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
This directory contains source files for the jNutList application.
|
||||
It allows to connect to an UPSD then retrieve devices and their variables.
|
||||
It is a little example application to show how to use jNut.
|
||||
|
||||
jNutList building
|
||||
^^^^^^^^^^^^^^^^^
|
||||
|
||||
As jNut, jNutList is a maven project so a maven environment must be set.
|
||||
Please reffer to jNut building notes.
|
||||
|
||||
jNutList running
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
jNutList can be run launching it in a console:
|
||||
|
||||
java -jar jNutList-x.x-xxx-jar-with-dependencies.jar
|
||||
|
||||
Some parameters can be passed :
|
||||
|
||||
java -jar jNutList-x.x-jar-with-dependencies.jar host port login password
|
||||
|
||||
For example:
|
||||
|
||||
java -jar jNutList-x.x-jar-with-dependencies.jar localhost 3493 admin passwd
|
||||
|
||||
By default, host is localhost, port is 3493 and login and password are not
|
||||
specified.
|
62
scripts/java/jNutList/pom.xml
Normal file
62
scripts/java/jNutList/pom.xml
Normal file
|
@ -0,0 +1,62 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.networkupstools</groupId>
|
||||
<artifactId>jNutList</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>jNutList</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jNut</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<!-- NOTE: We don't need a groupId specification because the group is
|
||||
org.apache.maven.plugins ...which is assumed by default.
|
||||
-->
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>org.networkupstools.jnutlist.AppList</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id> <!-- this is used for inheritance merges -->
|
||||
<phase>package</phase> <!-- bind to the packaging phase -->
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,112 @@
|
|||
/* AppList.java
|
||||
|
||||
Copyright (C) 2011 Eaton
|
||||
|
||||
This program 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.
|
||||
|
||||
This program 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 this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
package org.networkupstools.jnutlist;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
import org.networkupstools.jnut.*;
|
||||
|
||||
|
||||
public class AppList
|
||||
{
|
||||
|
||||
public static void main( String[] args )
|
||||
{
|
||||
String host = args.length>=1?args[0]:"localhost";
|
||||
int port = args.length>=2?Integer.valueOf(args[1]).intValue():3493;
|
||||
String login = args.length>=3?args[2]:"";
|
||||
String pass = args.length>=4?args[3]:"";
|
||||
|
||||
System.out.println( "jNutList connecting to " + login+":"+pass+"@"+host+":"+port );
|
||||
|
||||
Client client = new Client();
|
||||
try {
|
||||
client.connect(host, port, login, pass);
|
||||
Device[] devs = client.getDeviceList();
|
||||
if(devs!=null)
|
||||
{
|
||||
for(int d=0; d<devs.length; d++)
|
||||
{
|
||||
Device dev = devs[d];
|
||||
String desc = "";
|
||||
try {
|
||||
desc = " : " + dev.getDescription();
|
||||
} catch(NutException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("DEV " + dev.getName() + desc);
|
||||
|
||||
try {
|
||||
Variable[] vars = dev.getVariableList();
|
||||
if(vars!=null)
|
||||
{
|
||||
if(vars.length==0)
|
||||
System.out.println(" NO VAR");
|
||||
for(int v=0; v<vars.length; v++)
|
||||
{
|
||||
Variable var = vars[v];
|
||||
String res = "";
|
||||
try {
|
||||
res = " = " + var.getValue() + " (" + var.getDescription() + ")";
|
||||
} catch(NutException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println(" VAR " + var.getName() + res );
|
||||
}
|
||||
}
|
||||
else
|
||||
System.out.println(" NULL VAR");
|
||||
} catch(NutException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
Command[] cmds = dev.getCommandList();
|
||||
if(cmds!=null)
|
||||
{
|
||||
if(cmds.length==0)
|
||||
System.out.println(" NO CMD");
|
||||
for(int c=0; c<cmds.length; c++)
|
||||
{
|
||||
Command cmd = cmds[c];
|
||||
String res = "";
|
||||
try {
|
||||
res = " : " + cmd.getDescription();
|
||||
} catch(NutException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println(" CMD " + cmd.getName() + res);
|
||||
}
|
||||
}
|
||||
else
|
||||
System.out.println(" NULL CMD");
|
||||
} catch(NutException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
client.disconnect();
|
||||
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue