View Source

The following example demonstrates how to display the statuses of all Policies.

A PHP file called {{Get_Status_Of_All_Policies.php}} can be found in {{<installdir>/apisamples}}. Read more in [Accessing Example API Functions].

The PHP script searches all Policies in the the system and prints result messages on the screen, providing the following information:
* Policy ID, name, description, state, or "Failed to find all status of all policies."

h4. Sequence of Automated Actions

The following steps can be accomplished by using this script:

# Find all Policies.&nbsp;
# Display their ID, name, description, or state.

h4. How to Fulfill Appropriate Actions in CDP User Interface

Below, you can find the steps to perform these actions using the program user interface. Screen-shots are provided to illustrate the scripts for each step.

----
{toc:location=top|maxLevel=5|minLevel=5|type=flat|separator=pipe|style=border:1}
----
h5. Defining server configuration variables

{code}########====CDP Server Configuration Start====########
#set CDP server host name
$HOST="127.0.0.1";
#set CDP server to access API
$PORT="9443";
#set CDP user
$USER="admin";
#set CDP user password
$PASS="admin";
########====CDP Server Configuration End====########{code}

Log in to the CDP Server user interface using your username and password.

!login.png!

h5. Displaying Policies' States

{code}
try{
$policyClient = new soapclient("https://$HOST:$PORT/Policy2?wsdl",
array(
'login'=>"$USER",
'password'=>"$PASS",
'trace'=>1,
'cache_wsdl' => WSDL_CACHE_NONE,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS)
);

$allPoliciesForUser = $policyClient->getPolicies();

foreach($allPoliciesForUser->return as $tmp)
{
echo "$tmp->id \n";
echo "$tmp->name \n";
echo "$tmp->description \n";
if ($tmp->state == "UNKNOWN"){
echo "Policy is in a UNKNOWN state \n";
}
else if ($tmp->state == "ERROR"){
echo "Policy has ERROR \n";
}
else if ($tmp->state == "ALERT"){
echo "Policy has ALERT(s) \n";
}
else {
echo "Policy State is OK \n";
}

echo "\n";
}

exit(0);

}
catch (SoapFault $exception)
{
echo "Failed to find all status of all policies";
echo $exception;
exit(1);
}


?>

{code}

1. Click on "Policy" in the Main Menu to open the "Policies" window.

!menu-policy.png!

2. Click on the "Show All" button located in the top right-hand corner of the interface to show the list of all Policies.

!show-all.png!

3. The Policy State is graphically displayed in the "State" column. The green icon indicates the Policies that run without errors; the yellow icon indicates the Policies that have warnings while processing; the red icon indicates the Policies that run with errors; the blue icon indicates the Policies with an unknown state. If nothing is shown in this column, then the State is OK.

!state-column.png!

If one or more Policy runs with errors, the "Error" icon is displayed in the upper area of the interface, proceeded by a table containing information on the Policies' statuses.


!not_ok.png!


Read more about this panel in [Accessing Policies].