adding macosx device agent implementation

application-manager-new
buddhinipun 8 years ago
parent c1f3a670b5
commit e02f9bf4a5

@ -22,6 +22,7 @@ import java.io.IOException;
import org.json.JSONObject;
import org.wso2.agent.common.Common;
import org.wso2.agent.config.Configuration;
import org.wso2.agent.resourcemonitor.pojo.SystemUsage;
import com.sun.jersey.api.client.Client;
@ -36,7 +37,8 @@ public class PushSystemUsage {
try {
Client client = Client.create(Common.configureClient());
client.setConnectTimeout(50000);
WebResource webResource = client.resource("https://localhost:9443/connected-lap-agent/push_data");
String URL= String.valueOf(new Configuration().getInitProperty("https-ep"));
WebResource webResource = client.resource(URL+"/connected-lap-agent/push_data");
Form form = new Form();
form.add("deviceId", deviceid);
form.add("deviceOwner", owner);

@ -72,12 +72,12 @@ public class JavaApp {
Configuration config = new Configuration();
try {
String token = String.valueOf(config.getInitProperty("auth-token"));
//token="9c7a1b4d6625cdd936b894cc0e7c7390";
String refreshtoken = String.valueOf(config.getInitProperty("refresh-token"));
String device_name = String.valueOf(config.getInitProperty("device-name"));
Client client = Client.create(Common.configureClient());
client.setConnectTimeout(50000);
WebResource webResource = client.resource("https://localhost:9443/CONNECTEDLAP/device/register");
String URL= String.valueOf(new Configuration().getInitProperty("https-ep"));
WebResource webResource = client.resource(URL+"/CONNECTEDLAP/device/register");
String mac = spec.getMacaddress().replaceAll("\\:", "");
deviceid = mac;

@ -63,7 +63,7 @@ public class Collector {
return spec;
}
public SystemUsage getSysUsage(String suPassword) throws NumberFormatException, Exception {
public SystemUsage getSysUsage(String suPassword) throws Exception {
SystemUsage systemUsage = new SystemUsage();
BashRunner bashRunner = new BashRunner();
systemUsage.setMacaddress(bashRunner.runScript(this.OS, 0,suPassword));

@ -43,29 +43,55 @@ public class BashRunner {
private String[] getScript(String os, int scriptid,String suPassword) throws OperationalException {
String script[] = null;
try {
if(os.equalsIgnoreCase("LINUX")) {
if (scriptid == 0)
script = new String[]{ "/bin/sh", "-c", "ifconfig -a | awk '/^[a-z]/ { iface=$1; mac=$NF; next } /inet addr:/ { print mac }' | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'"+" | tr '\n' ' '"};
script = new String[]{"/bin/sh", "-c", "ifconfig -a | awk '/^[a-z]/ { iface=$1; mac=$NF; next } /inet addr:/ { print mac }' | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'" + " | tr '\n' ' '"};
if (scriptid == 1)
script = new String[]{ "/bin/sh", "-c", "cat /proc/cpuinfo |grep 'model name' | uniq | awk '{print substr($0, index($0,$4))}'"+" | tr '\n' ' '"};
if(scriptid==2)
script = new String[]{ "/bin/sh", "-c", "cat /proc/cpuinfo |grep 'cpu cores' | awk '{print substr($0, index($0,$4))}' | xargs | sed -e 's/\\ /+/g' | bc"+" | tr '\n' ' '"};
if(scriptid==3)
script = new String[]{ "/bin/sh", "-c", "echo "+suPassword+" | sudo -S dmidecode -t 17 | grep 'Size.*MB' | awk '{s+=$2} END {print s / 1024}'"+" | tr '\n' ' '"};
if(scriptid==4)
script = new String[]{"/bin/sh", "-c", "cat /proc/cpuinfo |grep 'model name' | uniq | awk '{print substr($0, index($0,$4))}'" + " | tr '\n' ' '"};
if (scriptid == 2)
script = new String[]{"/bin/sh", "-c", "cat /proc/cpuinfo |grep 'cpu cores' | awk '{print substr($0, index($0,$4))}' | xargs | sed -e 's/\\ /+/g' | bc" + " | tr '\n' ' '"};
if (scriptid == 3)
script = new String[]{"/bin/sh", "-c", "echo " + suPassword + " | sudo -S dmidecode -t 17 | grep 'Size.*MB' | awk '{s+=$2} END {print s / 1024}'" + " | tr '\n' ' '"};
if (scriptid == 4)
// script = new String[]{ "/bin/sh", "-c", "echo Amilapwd1 | sudo -S hdparm -I /dev/sda |grep 'device size with M = 1000\\*1000' | awk '{print substr($0, index($0,$9))}' | awk -F'[\t(]' '{print $2}' | awk '{print substr($1,0)}'"+" | tr '\n' ' '"};
script = new String[]{ "/bin/sh", "-c", "echo "+suPassword+" | sudo -S fdisk -l | grep 'Disk /dev/sda' | awk '{print $3}'"+" | tr '\n' ' '"};
if(scriptid==5)
script = new String[]{ "/bin/sh", "-c", "echo "+suPassword+" | sudo -S hdparm -I /dev/sda |grep 'device size with M = 1000\\*1000' | awk '{print $0}' | awk -F'[\t(]' '{print $2}' | awk '{print substr($1,0)}'"+" | tr '\n' ' '"};
if(scriptid==10)
script = new String[]{ "/bin/sh", "-c", "top -b -n2 | grep 'Cpu(s)' | tail -n 1 | awk '{print $2 + $4}'"+" | tr '\n' ' '"};
if(scriptid==11)
script = new String[]{ "/bin/sh", "-c", "free | grep Mem | awk '{print $3/$2 * 100.0}'"+" | tr '\n' ' '"};
if(scriptid==12)
script = new String[]{ "/bin/sh", "-c", "df -h | grep -vE '^Filesystem' | awk '{ print $1\" \"$3\" \"$2 }' | grep \"/\" | awk 'NF{sum1+=$2} NF{sum2+=$3} END {print (sum1/sum2)*100}'"+" | tr '\n' ' '"};
if(scriptid==13)
script = new String[]{ "/bin/sh", "-c", "upower -i $(upower -e | grep BAT) | grep -E 'percentage' | awk '{ print $2 }' | tr '%' ' '"+" | tr '\n' ' '"};
if(scriptid==14)
script = new String[]{ "/bin/sh", "-c", "upower -i $(upower -e | grep BAT) | grep -E 'state' | awk '{ if($2==\"charging\"||$2==\"fully-charged\") print 1; else print 0; }'"+" | tr '\n' ' '"};
script = new String[]{"/bin/sh", "-c", "echo " + suPassword + " | sudo -S fdisk -l | grep 'Disk /dev/sda' | awk '{print $3}'" + " | tr '\n' ' '"};
if (scriptid == 5)
script = new String[]{"/bin/sh", "-c", "echo " + suPassword + " | sudo -S hdparm -I /dev/sda |grep 'device size with M = 1000\\*1000' | awk '{print $0}' | awk -F'[\t(]' '{print $2}' | awk '{print substr($1,0)}'" + " | tr '\n' ' '"};
if (scriptid == 10)
script = new String[]{"/bin/sh", "-c", "top -b -n2 | grep 'Cpu(s)' | tail -n 1 | awk '{print $2 + $4}'" + " | tr '\n' ' '"};
if (scriptid == 11)
script = new String[]{"/bin/sh", "-c", "free | grep Mem | awk '{print $3/$2 * 100.0}'" + " | tr '\n' ' '"};
if (scriptid == 12)
script = new String[]{"/bin/sh", "-c", "df -h | grep -vE '^Filesystem' | awk '{ print $1\" \"$3\" \"$2 }' | grep \"/\" | awk 'NF{sum1+=$2} NF{sum2+=$3} END {print (sum1/sum2)*100}'" + " | tr '\n' ' '"};
if (scriptid == 13)
script = new String[]{"/bin/sh", "-c", "upower -i $(upower -e | grep BAT) | grep -E 'percentage' | awk '{ print $2 }' | tr '%' ' '" + " | tr '\n' ' '"};
if (scriptid == 14)
script = new String[]{"/bin/sh", "-c", "upower -i $(upower -e | grep BAT) | grep -E 'state' | awk '{ if($2==\"charging\"||$2==\"fully-charged\") print 1; else print 0; }'" + " | tr '\n' ' '"};
}else{
if (scriptid == 0)//mac
script = new String[]{"/bin/sh", "-c", "ifconfig en1 | awk '/ether/{print $2}'" + " | tr '\n' ' '"};
if (scriptid == 1)//processor
script = new String[]{"/bin/sh", "-c", "sysctl -n machdep.cpu.brand_string" + " | tr '\n' ' '"};
if (scriptid == 2)//cores
script = new String[]{"/bin/sh", "-c", "sysctl -n hw.ncpu" + " | tr '\n' ' '"};
if (scriptid == 3)//ram size
script = new String[]{"/bin/sh", "-c", "sysctl -n hw.memsize | awk '{print $1 / 1048576}'" + " | tr '\n' ' '"};
if (scriptid == 4)//storage
// script = new String[]{ "/bin/sh", "-c", "echo Amilapwd1 | sudo -S hdparm -I /dev/sda |grep 'device size with M = 1000\\*1000' | awk '{print substr($0, index($0,$9))}' | awk -F'[\t(]' '{print $2}' | awk '{print substr($1,0)}'"+" | tr '\n' ' '"};
script = new String[]{"/bin/sh", "-c", "diskutil list | grep 'GUID_partition_scheme' | awk '{ print $3}' | sed 's/*//g' | awk '{s+=$0} END {print s}'" + " | tr '\n' ' '"};
if (scriptid == 5)//
script = new String[]{"/bin/sh", "-c", "echo " + suPassword + " | sudo -S hdparm -I /dev/sda |grep 'device size with M = 1000\\*1000' | awk '{print $0}' | awk -F'[\t(]' '{print $2}' | awk '{print substr($1,0)}'" + " | tr '\n' ' '"};
if (scriptid == 10)//processor usage
script = new String[]{"/bin/sh", "-c", "ps -A -o %cpu | awk '{s+=$1} END {print s}'" + " | tr '\n' ' '"};
if (scriptid == 11)//memory usage
script = new String[]{"/bin/sh", "-c", "free | grep Mem | awk '{print $3/$2 * 100.0}'" + " | tr '\n' ' '"};
if (scriptid == 12)//storage usage
script = new String[]{"/bin/sh", "-c", "df -h | grep -vE '^Filesystem' | awk '{ print $1\" \"$3\" \"$2 }' | grep \"/\" | awk 'NF{sum1+=$2} NF{sum2+=$3} END {print (sum1/sum2)*100}'" + " | tr '\n' ' '"};
if (scriptid == 13)//batttery percentage
script = new String[]{"/bin/sh", "-c", "pmset -g batt | grep \"InternalBattery\" | awk '{print $2}' | sed 's/%;//g'" + " | tr '\n' ' '"};
if (scriptid == 14)//charger plugged in
script = new String[]{"/bin/sh", "-c", "pmset -g batt | grep \"InternalBattery\" | awk '{print $3}' | sed 's/;//g' | awk '{ if($0==\"charging\"||$0==\"charged\") print 1; else print 0; }'" + " | tr '\n' ' '"};
}
} catch (Exception e) {
}

Loading…
Cancel
Save