You are here: Smart Control > Smart Control Classes > Server Class (server)

Server Class (server)

The following are Server parameters. Refer to Server Commands for descriptions.

Parameters

name (string)

proto (string)

probe_l3 (bool)

ip (string)

max_reuse_conn (int)

port (int)

reuse_conn_timeout (int)

Methods

getByName(string name)

 

Description:

Fetch the server named ‘name’ from the configuration.

 

Returns:

On success: server object populated with all of its properties.  On failure: An exception with a message and an error code.

 

Example:

// Fetch a server named ‘sv00’

$sv = server::getByName("sv00");

getStatusDescription()

 

Description:

Get the status of this server as a string.

 

Returns:

A string containing the status of this server.

 

Example:

$sv = server::getByName(“sv00”);

// print the status – accessible using ‘lastrun’ command.

echo $sv->getStatusDescription();

getStatusResp()

 

Description:

Get the status of this server as a numeric value.

 

Returns: A numeric value indicating the status:

0: There are no problems with this server.

1: There is an ‘informational’ status available, but the server is functional.

2: There is a problem with this server.

Example:

// If there is a problem with this server, print the status (accessible using ‘lastrun’ command).

$sv = server::getByName(“sv00”);

if ($sv->getStatusResp() == 2) {

        echo $sv->getStatusDescription();

}

getVid ()

 

Description:

Get the VID that the system thinks this server belongs on.

 

Returns:

A string value indicating the VID, or “unassigned” if no appropriate network is found.

 

Example:

// Print out ‘unknown’ or ‘known’ network, accessible using the ‘lastrun’ command.

$sv = server::getByName(“sv00”);

if ($sv->getVid() == "unassigned") {

echo "Unknown network";

} else {

       echo "Known network";

}

stats(string statName)

 

Description:

Get the value of the statistic named ‘statName’.  The available statistics are the same as those displayed in the CLI when using the server <name>stats command.

 

Returns:

On success, the last-measured value of this statistic. On failure, an exception describing what went wrong: invalid statistic name or no statistic specified.

 

Example:

$sv = server::getByName(“sv00”);

if ($sv->stats(“TOTALPRCSD”) > 100) {

        echo “Processed more than 100 requests through sv00”;

}

delete(optional Boolean forceFlag)

 

Description:

Delete this server.  Can only be used on a server object which has been retrieved using server:: getByName(), and it must not have been modified since the last time that it was retrieved.  If the server is in use by another object in the system, the flag forceFlag must be set to ‘TRUE’ in order for it to be deleted.

 

Returns:

Map containing message string with a status code.  Status code will be 0 if the deletion was successful and non-zero otherwise.

 

Example:

$sv = server::getByName(“sv00”);

// Try to delete it, if it fails, force the deletion.

$value = $sv->delete();

if ($value[“status”] != 0) {

    // Print out the reason for the failure, accessible using ‘lastrun’ command

    echo “Failed to delete because: “, $value[“message”];

    $value = $sv->delete(TRUE);

}

commit()

 

Description:

Push the changes to this server into the permanent configuration. If this server object was created using getByName(), this operation is treated as a modify. If it was created using the new keyword, it is treated as an addition.

 

Returns:

Map containing message string with a status code.  Status code will be 0 if the commit was successful and non-zero otherwise.

 

Example:

// Create a new server, then modify it

$sv = new server;

$sv->name = "newsv";

$sv->proto = "tcp";

$sv->ip = "1.2.3.4";

$sv->port = 80;

$sv->commit();

 

// If we don’t do getByName(), the commit() below would fail with ‘object already exists’ error because the system will try to add this object instead of modify it.

$sv = server::getByName("newsv");

$sv->port = 443;

$sv->commit();