{"id":15984890,"url":"https://github.com/divineomega/cachet.php","last_synced_at":"2025-03-16T07:32:01.760Z","repository":{"id":32330933,"uuid":"35906291","full_name":"DivineOmega/cachet.php","owner":"DivineOmega","description":"📛 PHP client library for the Cachet API","archived":false,"fork":false,"pushed_at":"2021-04-25T13:42:15.000Z","size":103,"stargazers_count":38,"open_issues_count":4,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-27T05:49:33.781Z","etag":null,"topics":["cachet","php-library"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DivineOmega.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-19T20:19:07.000Z","updated_at":"2024-01-30T14:15:37.000Z","dependencies_parsed_at":"2022-08-21T06:40:14.197Z","dependency_job_id":null,"html_url":"https://github.com/DivineOmega/cachet.php","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DivineOmega%2Fcachet.php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DivineOmega%2Fcachet.php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DivineOmega%2Fcachet.php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DivineOmega%2Fcachet.php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DivineOmega","download_url":"https://codeload.github.com/DivineOmega/cachet.php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243806045,"owners_count":20350775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cachet","php-library"],"created_at":"2024-10-08T02:11:07.158Z","updated_at":"2025-03-16T07:32:01.284Z","avatar_url":"https://github.com/DivineOmega.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cachet.php\n\ncachet.php is a PHP client library for the Cachet status page (https://cachethq.io/).\n\nThis library could be useful for displaying details from your Cachet status page in other systems, such as a monitoring dashboard, a client ticketing system or any other web applications.\n\nIf you want to grab cachet.php with Composer, take a look on Packagist: https://packagist.org/packages/divineomega/cachetphp\n\n# Quick Start\n\nBefore starting, install the cachet.php library via Composer.\n\n## Create CachetInstance object\n\nNow, you need to create a CachetInstance object that represents your installation of Cachet. You can do this like so:\n\n```php\nrequire_once 'vendor/autoload.php';\n\nuse \\DivineOmega\\CachetPHP\\Factories\\CachetInstanceFactory;\n\n// The API token for the demo instance is 9yMHsdioQosnyVK4iCVR.\n$cachetInstance = CachetInstanceFactory::create('https://demo.cachethq.io/api/v1/', '9yMHsdioQosnyVK4iCVR');\n```\n\n## Retrieving Cachet elements\n\nRetrieving data from the various elements of your Cachet instance is easy. Just call the appropriate getter method on your ```$cachetInstance``` object. The Cachet install will be contacted and an array of request appropriate objects be returned.\n\n```php\n$components = $cachetInstance-\u003egetAllComponents();         // Components\n$incidents = $cachetInstance-\u003egetAllIncidents();           // Incidents\n$incidentUpdates = $incidents[0]-\u003egetAllIncidentUpdates(); // Incident Updates (Cachet 2.4.0 or above required)\n$metrics = $cachetInstance-\u003egetAllMetrics();               // Metrics\n$metricPoints = $metrics[0]-\u003egetAllMetricPoints();         // Metric Points\n$subscribers = $cachetInstance-\u003egetAllSubscribers();       // Subscribers\n```\n\nTo retrieve a single Cachet element by its ID, you can use code similar to the following method.\n\n```php\n// Get incident by id\n$incident = $cachetInstance-\u003egetIncidentById($incidentId);\n```\n\n### Sorting Cachet elements\n\nIf you wish to sort your results, you can use the following syntax. This works for components, incidents, metrics, metric points and subscribers.\n\n```php\n// Get components sorted by name ascending\n$components = $cachetInstance-\u003egetAllComponents('name', 'asc');\n```\n\n## Reading from Cachet element objects\n\nReading data from retrieved Cachet element objects is easy. Just access their public member variables.\n\nHere's an example of outputting the id, name, description and status of a Cachet component.\n\n```php\n// Get components\n$components = $cachetInstance-\u003egetAllComponents();\n\n// Display components\nforeach ($components as $component) {\n    echo $component-\u003eid.' - '.$component-\u003ename.' - '.$component-\u003edescription.' - '.$component-\u003estatus;\n    echo \"\u003cbr/\u003e\";\n}\n```\n\nSee the [official Cachet documentation](https://docs.cachethq.io/docs) for information on the variables available for each type of Cachet element.\n\n## Creating Cachet elements\n\nYou can create a Cachet element, such as a component or incident very easily using the cachet.php library. This involves creating an associative array of the details for the Cachet elements and then passing this to the relevant creation method.\n\nThe following example shows you how to make a simple test component.\n\n```php\n$componentDetails = ['name' =\u003e 'Test Component '.rand(1, 99999), 'status' =\u003e 1];\n\n$component = $cachetInstance-\u003ecreateComponent($componentDetails);\n\necho $component-\u003eid.' - '.$component-\u003ename.' - '.$component-\u003edescription.' - '.$component-\u003estatus;\n```\n\nThe more comprehensive example below shows how to create an incident and add an incident update to it. \nPlease note that Cachet 2.4.0 or above required if you wish to use incident updates.\n\n```php\n$incidentDetails = ['name' =\u003e 'Test Incident '.rand(1, 99999), 'message' =\u003e 'Incident message '.rand(1, 99999), 'status' =\u003e 1, 'visible' =\u003e 1];\n\n$incident = $cachetInstance-\u003ecreateIncident($incidentDetails);\n\n$incidentUpdateDetails = ['status' =\u003e 2, 'message' =\u003e 'Test incident update '.rand(1, 99999)];\n\n$incidentUpdate = $incident-\u003ecreateIncidentUpdate($incidentUpdateDetails);\n\necho $incidentUpdate-\u003eid.' - '.$incidentUpdate-\u003eincident_id.' - '.$incidentUpdate-\u003estatus.' - '.$incidentUpdate-\u003emessage;\n```\n\n## Updating Cachet elements\n\nThe cachet.php allows you to make changes to a Cachet element and saving those changes back to your Cachet install. This is done by directly changing the Cachet element's public member variables, and then calling the object's `save()` method.\n\nThe following example shows how to change the name and status of a component, then save the changes.\n\n```php\n// Get components\n$components = $cachetInstance-\u003egetAllComponents();\n\n// Change component details\n$component[0]-\u003ename = 'My awesome component';\n$component[0]-\u003estatus = 1;\n$component[0]-\u003esave();\n```\n\n### Updating Component Status via Incident and Incident Updates\n\nIf you create an incident with a `component_id`, you can also include a `component_status` to change the\ncomponent's status at the same time as creating the incident. See the example below.\n\n```php\n$incidentDetails = ['name' =\u003e 'Test Incident '.rand(1, 99999), 'message' =\u003e 'Incident message '.rand(1, 99999), 'status' =\u003e 1, 'visible' =\u003e 1,\n    'component_id' =\u003e 1, 'component_status' =\u003e 1];\n\n$incident = $cachetInstance-\u003ecreateIncident($incidentDetails);\n```\n\nWhen creating incident updates, you can also specify a `component_status` to change the component's status when the\nincident update is created. See the example below.\n\n```php\n$incidentUpdateDetails = ['status' =\u003e 2, 'message' =\u003e 'Test incident update '.rand(1, 99999), 'component_status' =\u003e 2];\n\n$incidentUpdate = $incident-\u003ecreateIncidentUpdate($incidentUpdateDetails);\n```\n\nYou can also change a component status via an incident or incident update by changing the `component_status` on the \nrelated object and saving, as shown below in the exmaples below. Note that this will only work if the incident was\ncreated with an assoicated `component_id`.\n\n```php\n$incident-\u003ecomponent_status = 2;\n$incident-\u003esave();\n```\n\n```php\n$incidentUpdate-\u003ecomponent_status = 3;\n$incidentUpdate-\u003esave();\n```\n\n## Deleting Cachet elements\n\nTo delete a Cachet element from your Cachet install, you simply need to call the `delete()` method on the appropriate Cachet element object.\n\nFor example, to delete an incident you could do the following.\n\n```php\n// Get incidents\n$incidents = $cachetInstance-\u003egetAllIncidents();\n\n// Delete the first one\n$incidents[0]-\u003edelete();\n```\n\n# Contact\n\nIf you've found a bug or a new feature, please [report it as a GitHub issue](https://github.com/DivineOmega/cachet.php/issues).\n\nFor other queries, I'm available on Twitter ([Jordan Hall](https://twitter.com/divineomega)).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdivineomega%2Fcachet.php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdivineomega%2Fcachet.php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdivineomega%2Fcachet.php/lists"}