function get_egfa($ip)
{
    require "genericSnmp.php";
    $mac = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.2.1.1.1.0");
    $ipadd = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.1.9.0");
    $value[0] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.2.0");
    $value[1] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.3.0");
    $value[2] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.4.1.4.1");
    $value[3] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.4.1.4.2");
    $value[4] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.4.1.4.3");
    $value[5] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.5.0");
    $value[6] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.6.0");
    $value[7] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.7.1.2.1");
    $value[8] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.7.1.2.2");
    $value[9] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.7.1.2.3");
    $value[10] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.7.1.2.4");
    $value[11] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.7.1.2.5");
    $value[12] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.7.1.2.6");
    $value[13] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.7.1.2.7");
    $value[14] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.7.1.2.8");
    $value[15] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.3.2.2.1.18.1");
    $value[16] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.3.2.2.1.19.1");
    $value[17] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.1.3.0");
    $value[18] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.1.4.0");
    $value[19] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.1.5.0");
    $value[20] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.1.10.0");
    $value[21] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.1.12.0");
    $value[22] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.1.13.0");
    $value[23] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.1.17.0");
    $lab[0] = "Output Optical Power";
    $lab[1] = "Input Optical Power";
    $lab[2] = "Pump Temperature 1";
    $lab[3] = "Pump Temperature 2";
    $lab[4] = "Pump Temperature 3";
    $lab[5] = "Number of DC Power Supply";
    $lab[6] = "DC Power Supply Mode";
    $lab[7] = "DC +5V";
    $lab[8] = "DC -5V";
    $lab[9] = "DC +3.3V";
    $lab[10] = "DC +12V";
    $lab[11] = "Left +5V";
    $lab[12] = "Right +5V";
    $lab[13] = "Left -5V";
    $lab[14] = "Right -5V";
    $lab[15] = "Device Manufactoring Date";
    $lab[16] = "Firmware Version";
    $lab[17] = "Model";
    $lab[18] = "Serial Number";
    $lab[19] = "Vendor";
    $lab[20] = "Check Code";
    $lab[21] = "Tamper Status";
    $lab[22] = "Internal Temperature";
    $lab[23] = "Craft Status";
    /////////////////////////////////////////////// for asset values
    $sysDescr = snmpget_bigP($ip, ".1.3.6.1.2.1.1.1.0");
    $sysObjectID = snmpget_bigP($ip, ".1.3.6.1.2.1.1.2.0");
    $sysUpTime = snmpget_bigP($ip, ".1.3.6.1.2.1.1.3.0");
    $sysContact = snmpget_bigP($ip, ".1.3.6.1.2.1.1.4.0");
    $sysName = snmpget_bigP($ip, ".1.3.6.1.2.1.1.5.0");
    $sysLocation = snmpget_bigP($ip, ".1.3.6.1.2.1.1.6.0");
    $sysService = snmpget_bigP($ip, ".1.3.6.1.2.1.1.7.0");
    // for testing purpose
    echo "EGFA Optical Amplifier <br>";
    echo "------------------------------------------------<br>";
    echo "\n\t<style>\n\n\ntable {\n    width:100%;\n}\n\ntable, th , td {\n    border: 1px solid grey;\n    border-collapse: collapse;\n    padding: 5px;\n}\n\nth {\n    text-align: left; \n}\n\ntable tr:nth-child(odd) {\n    background-color: #f1f1f1;\n}\ntable tr:nth-child(even) {\n    background-color: #ffffff;\n}\n\n\n\n\n\n\n\n\n\n\t</style>\n\t";
    echo "<table style=width:100%>";
    echo "<tr>";
    echo "<td>Description</td>";
    echo "<td>" . $sysDescr . "</td>";
    echo "</tr><tr>";
    echo "<td>ObjectID</td>";
    echo "<td>" . $sysObjectID . "</td>";
    echo "</tr><tr>";
    echo "<td>IP</td>";
    echo "<td>" . $ipadd . "</td>";
    echo "</tr><tr>";
    echo "<td>MAC</td>";
    echo "<td>" . $mac . "</td>";
    echo "</tr><tr>";
    echo "<td>Up Time</td>";
    echo "<td>" . $sysUpTime . "</td>";
    echo "</tr><tr>";
    echo "<td>Contact</td>";
    echo "<td>" . $sysContact . "</td>";
    echo "</tr><tr>";
    echo "<td>Name</td>";
    echo "<td>" . $sysName . "</td>";
    echo "</tr><tr>";
    echo "<td>Location</td>";
    echo "<td>" . $sysLocation . "</td>";
    echo "</tr><tr>";
    echo "<td>Service</td>";
    echo "<td>" . $sysService . "</td>";
    echo "</tr>";
    for ($i = 0; $i < 24; $i++) {
        echo "<tr>";
        echo "<td>" . $lab[$i] . "</td>";
        echo "<td>" . $value[$i] . "</td>";
        echo "</tr>";
    }
}
$lab[16] = "Firmware Version";
$lab[17] = "Model";
$lab[18] = "Serial Number";
$lab[19] = "Vendor";
$lab[20] = "Check Code";
$lab[21] = "Tamper Status";
$lab[22] = "Internal Temperature";
$lab[23] = "Craft Status";
/////////////////////////////////////////////// for asset values
$sysDescr = snmpget_bigP($ip, ".1.3.6.1.2.1.1.1.0");
$sysObjectID = snmpget_bigP($ip, ".1.3.6.1.2.1.1.2.0");
$sysUpTime = snmpget_bigP($ip, ".1.3.6.1.2.1.1.3.0");
$sysContact = snmpget_bigP($ip, ".1.3.6.1.2.1.1.4.0");
$sysName = snmpget_bigP($ip, ".1.3.6.1.2.1.1.5.0");
$sysLocation = snmpget_bigP($ip, ".1.3.6.1.2.1.1.6.0");
$sysService = snmpget_bigP($ip, ".1.3.6.1.2.1.1.7.0");
// for testing purpose
echo "EGFA Optical Amplifier <br>";
echo "------------------------------------------------<br>";
echo "IP Address: " . $ipadd . "<br>";
echo "MAC: " . $mac . "<br>";
for ($i = 0; $i < 24; $i++) {
    echo $lab[$i] . " : " . $value[$i] . "<br>";
}
echo "------------------------------------------------<br>";
echo $sysDescr . "<br>";
echo $sysObjectID . "<br>";
echo $sysUpTime . "<br>";
echo $sysContact . "<br>";
echo $sysName . "<br>";
echo $sysLocation . "<br>";
function writeToDatabase($ip, $s)
{
    $deco_ip = "'" . $ip . "'";
    $timestamp = "'" . date('YmdGis') . "'";
    $status = "'" . "online" . "'";
    if ($s == "public") {
        # code...
        $sysDescr = "'" . snmpget_smallp($ip, ".1.3.6.1.2.1.1.1.0") . "'";
        $sysObjectID = "'" . snmpget_smallp($ip, ".1.3.6.1.2.1.1.2.0") . "'";
        $sysUpTime = "'" . snmpget_smallp($ip, ".1.3.6.1.2.1.1.3.0") . "'";
        $sysContact = "'" . snmpget_smallp($ip, ".1.3.6.1.2.1.1.4.0") . "'";
        $sysName = "'" . snmpget_smallp($ip, ".1.3.6.1.2.1.1.5.0") . "'";
        $sysLocation = "'" . snmpget_smallp($ip, ".1.3.6.1.2.1.1.6.0") . "'";
        $sysService = "'" . snmpget_smallp($ip, ".1.3.6.1.2.1.1.7.0") . "'";
    }
    if ($s == "PUBLIC") {
        # code...
        $sysDescr = "'" . snmpget_bigP($ip, ".1.3.6.1.2.1.1.1.0") . "'";
        $sysObjectID = "'" . snmpget_bigP($ip, ".1.3.6.1.2.1.1.2.0") . "'";
        $sysUpTime = "'" . snmpget_bigP($ip, ".1.3.6.1.2.1.1.3.0") . "'";
        $sysContact = "'" . snmpget_bigP($ip, ".1.3.6.1.2.1.1.4.0") . "'";
        $sysName = "'" . snmpget_bigP($ip, ".1.3.6.1.2.1.1.5.0") . "'";
        $sysLocation = "'" . snmpget_bigP($ip, ".1.3.6.1.2.1.1.6.0") . "'";
        $sysService = "'" . snmpget_bigP($ip, ".1.3.6.1.2.1.1.7.0") . "'";
    }
    require "daemon_db_init.php";
    $query_exist = "SELECT relname FROM pg_class \n\tWHERE relname = 'daemondevice';";
    $result_exist = pg_query($query_exist) or die('Query failed: ' . pg_last_error());
    $exist = '';
    while ($row_exist = pg_fetch_object($result_exist)) {
        $exist = $row_exist->relname;
    }
    // // 3, if not existed, create it
    if ($exist != "daemondevice") {
        # code...
        $query_construct = "CREATE TABLE PUBLIC.daemondevice(\n\t\t\tid SERIAL PRIMARY KEY,\n\t\t\ttime           TEXT    ,\n\t\t\tip\t\tinet,\n\t\t\tstatus   \t\tTEXT,\n\t\t\tdescription            TEXT  ,\n\t\t\tmib    TEXT,\n\t\t\tuptime       TEXT,\n\t\t\tcontact       TEXT,\n\t\t\tname         TEXT,\n\t\t\tlocation\t\tTEXT,\n\t\t\tservice   TEXT,\n\t\t\tlatitude NUMERIC,\n\t\t\tlongtitude NUMERIC,\n\t\t\tMAC macaddr,\n\t\t\tsn TEXT,\n\t\t\tprovision TEXT);";
        $result_construct = pg_query($query_construct) or die('Query failed: ' . pg_last_error());
        pg_free_result($result_construct);
    }
    $query_value = "SELECT \n\t  daemondevice.ip\n\tFROM \n\t  public.daemondevice\n\tWHERE \n\t  daemondevice.ip = {$deco_ip};";
    $result_value = pg_query($query_value) or die('Query failed: ' . pg_last_error());
    $number = pg_num_rows($result_value);
    // the number of total device eg1550
    $method = "'" . "discover" . "'";
    if ($number == 0) {
        # code...
        $query_insert = "INSERT INTO PUBLIC.daemondevice (time, ip, status, description, mib, uptime, contact, name, location, service, provision) VALUES ({$timestamp}, {$deco_ip}, {$status}, {$sysDescr}, {$sysObjectID}, {$sysUpTime}, {$sysContact}, {$sysName}, {$sysLocation}, {$sysService}, {$method});";
        $result_insert = pg_query($query_insert) or die('Query failed: ' . pg_last_error());
        pg_free_result($result_insert);
    }
    pg_free_result($result_exist);
    pg_free_result($result_value);
    pg_close($dbconn);
}
function addDevice($ip, $comm, $mac, $sn, $lati, $long)
{
    $genericSnmpPath = $_SERVER["DOCUMENT_ROOT"] . "/vanguardhe/php_scripts/oidget/genericSnmp.php";
    require_once $genericSnmpPath;
    // to initialize snmp
    $deco_ip = "'" . $ip . "'";
    if ($mac == "") {
        # code...
        $mac = "00:00:00:00:00:00";
    }
    if ($sn == "") {
        # code...
        $sn = "NA";
    }
    if ($lati == "") {
        # code...
        $lati = "-73.6602109";
    }
    if ($long == "") {
        # code...
        $long = "45.5263402";
    }
    $deco_mac = "'" . $mac . "'";
    $deco_sn = "'" . $sn . "'";
    $timestamp = "'" . date('YmdGis') . "'";
    $status = "'" . "online" . "'";
    if ($comm == "public") {
        # code...
        $sysDescr = "'" . snmpget_smallp($ip, ".1.3.6.1.2.1.1.1.0") . "'";
        $sysObjectID = "'" . snmpget_smallp($ip, ".1.3.6.1.2.1.1.2.0") . "'";
        $sysUpTime = "'" . snmpget_smallp($ip, ".1.3.6.1.2.1.1.3.0") . "'";
        $sysContact = "'" . snmpget_smallp($ip, ".1.3.6.1.2.1.1.4.0") . "'";
        $sysName = "'" . snmpget_smallp($ip, ".1.3.6.1.2.1.1.5.0") . "'";
        $sysLocation = "'" . snmpget_smallp($ip, ".1.3.6.1.2.1.1.6.0") . "'";
        $sysService = "'" . snmpget_smallp($ip, ".1.3.6.1.2.1.1.7.0") . "'";
    }
    if ($comm == "PUBLIC") {
        # code...
        $sysDescr = "'" . snmpget_bigP($ip, ".1.3.6.1.2.1.1.1.0") . "'";
        $sysObjectID = "'" . snmpget_bigP($ip, ".1.3.6.1.2.1.1.2.0") . "'";
        $sysUpTime = "'" . snmpget_bigP($ip, ".1.3.6.1.2.1.1.3.0") . "'";
        $sysContact = "'" . snmpget_bigP($ip, ".1.3.6.1.2.1.1.4.0") . "'";
        $sysName = "'" . snmpget_bigP($ip, ".1.3.6.1.2.1.1.5.0") . "'";
        $sysLocation = "'" . snmpget_bigP($ip, ".1.3.6.1.2.1.1.6.0") . "'";
        $sysService = "'" . snmpget_bigP($ip, ".1.3.6.1.2.1.1.7.0") . "'";
    }
    if ($comm != "PUBLIC" && $comm != "public") {
        # code...
        $sysDescr = "'" . snmpget_generic($ip, $comm, ".1.3.6.1.2.1.1.1.0") . "'";
        $sysObjectID = "'" . snmpget_generic($ip, $comm, ".1.3.6.1.2.1.1.2.0") . "'";
        $sysUpTime = "'" . snmpget_generic($ip, $comm, ".1.3.6.1.2.1.1.3.0") . "'";
        $sysContact = "'" . snmpget_generic($ip, $comm, ".1.3.6.1.2.1.1.4.0") . "'";
        $sysName = "'" . snmpget_generic($ip, $comm, ".1.3.6.1.2.1.1.5.0") . "'";
        $sysLocation = "'" . snmpget_generic($ip, $comm, ".1.3.6.1.2.1.1.6.0") . "'";
        $sysService = "'" . snmpget_generic($ip, $comm, ".1.3.6.1.2.1.1.7.0") . "'";
    }
    require_once "daemon_db_init.php";
    $query_exist = "SELECT relname FROM pg_class \n\tWHERE relname = 'daemondevice';";
    $result_exist = pg_query($query_exist) or die('Query failed: ' . pg_last_error());
    $exist = '';
    while ($row_exist = pg_fetch_object($result_exist)) {
        $exist = $row_exist->relname;
    }
    // // 3, if not existed, create it
    if ($exist != "daemondevice") {
        # code...
        $query_construct = "CREATE TABLE PUBLIC.daemondevice(\n\t\t\tid SERIAL PRIMARY KEY,\n\t\t\ttime           TEXT    ,\n\t\t\tip\t\tinet,\n\t\t\tstatus   \t\tTEXT,\n\t\t\tdescription            TEXT  ,\n\t\t\tmib    TEXT,\n\t\t\tuptime       TEXT,\n\t\t\tcontact       TEXT,\n\t\t\tname         TEXT,\n\t\t\tlocation\t\tTEXT,\n\t\t\tservice   TEXT,\n\t\t\tlatitude NUMERIC,\n\t\t\tlongtitude NUMERIC,\n\t\t\tMAC macaddr,\n\t\t\tsn TEXT,\n\t\t\tprovision TEXT);";
        $result_construct = pg_query($query_construct) or die('Query failed: ' . pg_last_error());
        pg_free_result($result_construct);
    }
    $query_value = "SELECT \n\t  daemondevice.ip\n\tFROM \n\t  public.daemondevice\n\tWHERE \n\t  daemondevice.ip = {$deco_ip};";
    $result_value = pg_query($query_value) or die('Query failed: ' . pg_last_error());
    $number = pg_num_rows($result_value);
    // the number of total device eg1550
    $method = "'" . "add" . "'";
    if ($number == 0) {
        # code...
        $query_insert = "INSERT INTO PUBLIC.daemondevice (time, ip, status, description, mib, uptime, contact, name, location, service, latitude, longtitude, MAC, sn, provision) VALUES ({$timestamp}, {$deco_ip}, {$status}, {$sysDescr}, {$sysObjectID}, {$sysUpTime}, {$sysContact}, {$sysName}, {$sysLocation}, {$sysService}, {$lati}, {$long}, {$deco_mac}, {$deco_sn}, {$method});";
        $result_insert = pg_query($query_insert) or die('Query failed: ' . pg_last_error());
        pg_free_result($result_insert);
        echo $deco_ip . " has been inserted!<br>";
    }
    if ($number == 1) {
        $query_update = "UPDATE PUBLIC.daemondevice SET \n\t\t\ttime= {$timestamp}, \n\t\t\tip= {$deco_ip}, \n\t\t\tstatus = {$status},\n\t\t\tdescription = {$sysDescr},\n\t\t\tmib= {$sysObjectID},\n\t\t\tuptime = {$sysUpTime},\n\t\t\tcontact = {$sysContact},\n\t\t\tname = {$sysName},\n\t\t\tlocation= {$sysLocation},\n\t\t\tservice = {$sysService},\n\t\t\tlatitude={$lati},\n\t\t\tlongtitude= {$long},\n\t\t\tMAC = {$deco_mac},\n\t\t\tsn={$deco_sn},\n\t\t\tprovision = {$method}\n\t\t\tWHERE daemondevice.ip={$deco_ip};";
        $result_update = pg_query($query_update) or die('Query failed: ' . pg_last_error());
        pg_free_result($result_update);
        echo $deco_ip . " has been updated!<br>";
    }
    pg_free_result($result_exist);
    pg_free_result($result_value);
    //pg_close($dbconn);
}
function daemon_snmpScanIntoDb_egfa($ip)
{
    // TO-DO: 1) extract all snmp value from efga, 2) check if the table is existed, 3) if not existed, create it, and 4) put it into db. This action should be wrapped in a function.
    // header for initialization
    $genericSnmpPath = $_SERVER["DOCUMENT_ROOT"] . "/vanguardhe/php_scripts/oidget/genericSnmp.php";
    require_once $genericSnmpPath;
    // to initialize snmp
    require "daemon_db_init.php";
    // to initialize database connection
    require_once "daemon_getDeviceIdPerIp.php";
    // to initialize database connection
    // 1, extract all snmp value from efga
    //$timestamp = "'" . date('YmdGis') . "'";
    $deviceid = getDeviceIdPerIp($ip);
    global $timestamp;
    $sysDescr = deco_egfa(snmpget_bigP($ip, ".1.3.6.1.2.1.1.1.0"));
    $sysObjectID = deco_egfa(snmpget_bigP($ip, ".1.3.6.1.2.1.1.2.0"));
    $sysUpTime = deco_egfa(snmpget_bigP($ip, ".1.3.6.1.2.1.1.3.0"));
    $sysContact = deco_egfa(snmpget_bigP($ip, ".1.3.6.1.2.1.1.4.0"));
    $sysName = deco_egfa(snmpget_bigP($ip, ".1.3.6.1.2.1.1.5.0"));
    $sysLocation = deco_egfa(snmpget_bigP($ip, ".1.3.6.1.2.1.1.6.0"));
    $sysService = deco_egfa(snmpget_bigP($ip, ".1.3.6.1.2.1.1.7.0"));
    $defaultIp = trim(deco_egfa(snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.1.9.0")));
    $defaultMac = deco_egfa(snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.2.1.1.1.0"));
    $value[0] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.2.0");
    // "Output Optical Power"
    $value[1] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.3.0");
    // "Input Optical Power";
    $value[2] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.4.1.4.1");
    // "Pump Temperature 1";
    $value[3] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.4.1.4.2");
    //"Pump Temperature 2";
    $value[4] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.4.1.4.3");
    // "Pump Temperature 3";
    $value[5] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.5.0");
    //"Number of DC Power Supply";
    $value[6] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.6.0");
    //"DC Power Supply Mode";
    $value[7] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.7.1.2.1");
    // "DC +5V"
    $value[8] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.7.1.2.2");
    // "DC -5V";
    $value[9] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.7.1.2.3");
    // "DC +3.3V"
    $value[10] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.7.1.2.4");
    //  "DC +12V";
    $value[11] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.7.1.2.5");
    // "Left +5V"
    $value[12] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.7.1.2.6");
    // "Right +5V";
    $value[13] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.7.1.2.7");
    // "Left -5V";
    $value[14] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.11.7.1.2.8");
    //  "Right -5V";
    $value[15] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.3.2.2.1.18.1");
    // "Device Manufactoring Date";
    $value[16] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.3.2.2.1.19.1");
    // Firmware Version";
    $value[17] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.1.3.0");
    //   Model";
    $value[18] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.1.4.0");
    // Serial Number";
    $value[19] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.1.5.0");
    // "Vendor";
    $value[20] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.1.10.0");
    // Check Code";
    $value[21] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.1.12.0");
    // "Tamper Status";
    $value[22] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.1.13.0");
    // Internal Temperature";
    $value[23] = snmpget_bigP($ip, ".1.3.6.1.4.1.17409.1.3.1.17.0");
    // "Craft Status";
    for ($i = 0; $i < 24; $i++) {
        # code...
        $value[$i] = deco_egfa($value[$i]);
    }
    $lab[0] = "StatusIndex";
    $lab[1] = "IDcode";
    $lab[2] = "subID";
    $lab[3] = "FirmwareVersion";
    $lab[4] = "Laser IM";
    $lab[5] = "Laser Temperature (C)";
    $lab[6] = "Laser Bias";
    $lab[7] = "RF Modulation Level";
    $lab[8] = "DC24V Voltage";
    $lab[9] = "DC12V Voltage";
    $lab[10] = "DC5V Voltage";
    $lab[11] = "-5VDC Voltage";
    $lab[12] = "Tx Optical Power";
    $lab[13] = "Gain Control Setting";
    $lab[14] = "SBS CONTROL Setting";
    $lab[15] = "CTB_CONTROL_Setting";
    $lab[16] = "Tx RF Module Level";
    $lab[17] = "Present AC Power 1 status";
    $lab[18] = "Present AC Power 2 status";
    $lab[19] = "Tx AC Power supply status";
    // 2, check if the table "dameonSnmpEGFAValue" in the database "vanguardhe"
    $query_exist = "SELECT relname FROM pg_class \n\tWHERE relname = 'daemonsnmpegfavalue';";
    $result_exist = pg_query($query_exist) or die('Query failed: ' . pg_last_error());
    $exist = 'not here';
    while ($row_exist = pg_fetch_object($result_exist)) {
        $exist = $row_exist->relname;
    }
    // // 3, if not existed, create it
    if ($exist != "daemonsnmpegfavalue") {
        # code...
        $query_construct = "CREATE TABLE PUBLIC.daemonsnmpegfavalue(\n\t\t\tdeviceid\tint,\n\t\t\ttime           TEXT    ,\n\t\t\tdescription            TEXT  ,\n\t\t\toids       TEXT,\n\t\t\tuptime         TEXT,\n\t\t\tcontact         TEXT,\n\t\t\tname        TEXT,\n\t\t\tlocation         TEXT,\n\t\t\tservice        TEXT,\n\t\t\tip         TEXT,\n\t\t\tmac         TEXT,\n\t\t\toutputopticalpower            TEXT  ,\n\t\t\tinputopticalpower       TEXT,\n\t\t\tpumptemp1         TEXT,\n\t\t\tpumptemp2         TEXT,\n\t\t\tpumptemp3        TEXT,\n\t\t\tdcpsnumber        TEXT,\n\t\t\tdcpsmode        TEXT,\n\t\t\tdc5v         TEXT,\n\t\t\tdcminor5v         TEXT,\n\t\t\tdc33v            TEXT  ,\n\t\t\tdc12v      TEXT,\n\t\t\tleft5v         TEXT,\n\t\t\tright5v         TEXT,\n\t\t\tleftminor5v       TEXT,\n\t\t\trightminor5v        TEXT,\n\t\t\tmanudate       TEXT,\n\t\t\tfirmware         TEXT,\n\t\t\tmodel        TEXT,\n\t\t\tsn         TEXT,\n\t\t\tvendor       TEXT,\t\n\t\t\tcheckcode         TEXT,\n\t\t\ttamperstatus        TEXT,\n\t\t\tinternaltemp         TEXT,\n\t\t\tcraftstatus       TEXT\n\t\t\t);";
        $result_construct = pg_query($query_construct) or die('Query failed: ' . pg_last_error());
        pg_free_result($result_construct);
    }
    // 4, insert data into the table
    $query_insert = "INSERT INTO PUBLIC.daemonsnmpegfavalue VALUES ({$deviceid}, {$timestamp}, {$sysDescr}, {$sysObjectID}, {$sysUpTime}, {$sysContact}, {$sysName}, {$sysLocation}, \n\t\t{$sysService}, {$defaultIp}, {$defaultMac},  {$value['0']}, {$value['1']}, {$value['2']}, {$value['3']}, {$value['4']}, {$value['5']}, {$value['6']}, {$value['7']}, {$value['8']}, {$value['9']}, {$value['10']}, {$value['11']}, {$value['12']}, {$value['13']}, {$value['14']}, {$value['15']}, {$value['16']}, {$value['17']}, {$value['18']}, {$value['19']}, {$value['20']}, {$value['21']}, {$value['22']}, {$value['23']});";
    $result_insert = pg_query($query_insert) or die('Query failed: ' . pg_last_error());
    // 5, check if the table "daemonsnmpegfasummary" in the database "vanguardhe": this table is for the other maybe info further
    $query_exist_sum = "SELECT relname FROM pg_class \n\tWHERE relname = 'daemonsnmpegfasummary';";
    $result_exist_sum = pg_query($query_exist_sum) or die('Query failed: ' . pg_last_error());
    $exist_sum = '';
    while ($row_exist_sum = pg_fetch_object($result_exist_sum)) {
        $exist_sum = $row_exist_sum->relname;
    }
    // // 3, if not existed, create it
    if ($exist_sum != "daemonsnmpegfasummary") {
        # code...
        $query_construct_sum = "CREATE TABLE PUBLIC.daemonsnmpegfasummary(\n\t\t\tdescription\tText,\n\t\t\tcomments           TEXT  \t\t);";
        $result_construct_sum = pg_query($query_construct_sum) or die('Query failed: ' . pg_last_error());
        pg_free_result($result_construct_sum);
    }
    pg_free_result($result_exist);
    pg_free_result($result_insert);
    pg_free_result($result_exist_sum);
    pg_close($dbconn);
}