pax_global_header00006660000000000000000000000064122672574050014524gustar00rootroot0000000000000052 comment=1b5a6cc0cf83aa2f53cdcc5158ad088e7fd71d7e php-rrd-1.1.3/000077500000000000000000000000001226725740500131025ustar00rootroot00000000000000php-rrd-1.1.3/package.xml000066400000000000000000000216631226725740500152270ustar00rootroot00000000000000 rrd pecl.php.net PHP bindings to rrd tool system Procedural and simple OO wrapper for rrdtool - data logging and graphing system for time series data. Miroslav Kubelik koubel koubel@php.net yes 2014-01-15 1.1.3 1.1.3 stable stable BSD - rrdc_disconnect is available in rrd 1.4.0+ (Remi) 5.3.2 1.4.0 rrd 1.1.3 1.1.3 stable stable - rrdc_disconnect is available in rrd 1.4.0+ (Remi) 2014-01-15 1.1.2 1.1.2 stable stable - closing connection to rrd caching daemon #66088 - better documentation for RRDGraph::setOptions #65756 2014-01-14 1.1.1 1.1.1 stable stable - possible segfault in rrd_fetch 2013-09-03 1.1.0 1.1.0 stable stable - bug with multiple data sources in rrd_lastupdate - BC break #61316 2012-06-04 1.0.5 1.0.5 stable stable - license changed to the BSD license 2011-11-16 1.0.5RC2 1.0.5 beta stable - zts build fixed #59992 2011-10-17 1.0.5RC1 1.0.5 beta stable - config.m4 - lib searching rewritten, better support across architectures #22683 - RRDUpdater - multiple DS doesnt' work #23579 - better support for compiling under 5.2.x #22719 - small manual fixes 2011-09-27 1.0.4 1.0.4 stable stable - can be used with 5.4/trunk #22836 2011-08-12 1.0.3 1.0.3 stable stable - fixed installation for libs outside LDFLAGS #22666 2011-04-29 1.0.2 1.0.2 stable stable - fixed broken installation on FreeBSD #22651 2011-04-19 1.0.1 1.0.1 stable stable - fixed broken pecl installation #22644 2011-04-16 1.0.0 1.0.0 stable stable - fixed all reported bugs, mostly in test - rrd_version() added - better tests 2011-04-12 0.10.0 0.10.0 stable beta - fixed all reported bugs - fixed major bug in rrd_fetch #21402 - BC break : rdd_fetch returned array format changed, these items doesn't exist anymore - "ds_cnt", "ds_namv" 2011-03-03 0.9.0 0.9.0 beta beta first official pecl release 2011-01-03 php-rrd-1.1.3/rrd-1.1.3/000077500000000000000000000000001226725740500143275ustar00rootroot00000000000000php-rrd-1.1.3/rrd-1.1.3/CREDITS000066400000000000000000000002431226725740500153460ustar00rootroot00000000000000RRD Miroslav Kubelik Big Thanks: Joe Miller - author of first rrdtool extension Jeffrey Wheat, Dan Cech, Benny Baumann - patches and improvements php-rrd-1.1.3/rrd-1.1.3/LICENSE000066400000000000000000000024511226725740500153360ustar00rootroot00000000000000Copyright (c) 2010 - 2011, Miroslav KubelĂ­k All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. php-rrd-1.1.3/rrd-1.1.3/config.m4000066400000000000000000000046441226725740500160460ustar00rootroot00000000000000dnl config.m4 for extension php_rrd dnl Comments in this file start with the string 'dnl'. PHP_ARG_WITH(rrd, for rrdtool support, [ --with-rrd[=DIR] Include rrdtool support (requires rrdtool >= 1.3.x)]) AC_ARG_WITH(rrd-binary, [AC_HELP_STRING([--with-rrd-binary][=PATH], [rrd binary dir path, mostly for testing (default=$PATH)])], [AC_PATH_PROG(RRDTOOL_BIN, rrdtool, no, $withval)], [AC_PATH_PROG(RRDTOOL_BIN, rrdtool, no, $PATH)]) AC_SUBST(RRDTOOL_BIN) if test -f $srcdir/tests/rrdtool-bin.inc.in; then AC_OUTPUT(tests/rrdtool-bin.inc) AC_OUTPUT(tests/data/Makefile) fi if test "$PHP_RRD" != "no"; then if test "$PHP_RRD" != "yes"; then AC_MSG_CHECKING(if rrdtool specified path is valid) if test -r "$PHP_RRD/include/rrd.h"; then RRDTOOL_INCDIR=$PHP_RRD/include RRDTOOL_LIBDIR=$PHP_RRD/$PHP_LIBDIR AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) AC_MSG_ERROR([The specified RRDTool path is invalid or the installation is incomplete Please specify another path or reinstall the rrdtool distribution]) fi else AC_MSG_CHECKING([for rrdtool header files in default paths]) for i in /usr /usr/local /usr/local/rrdtool /opt; do test -r $i/include/rrd.h && RRDTOOL_LIBDIR=$i/$PHP_LIBDIR && RRDTOOL_INCDIR=$i/include done if test -z "$RRDTOOL_INCDIR"; then AC_MSG_RESULT([not found]) AC_MSG_ERROR([Please reinstall the rrdtool distribution]) else AC_MSG_RESULT(found in $RRDTOOL_INCDIR) fi fi dnl Finish the setup PHP_ADD_INCLUDE($RRDTOOL_INCDIR) PHP_CHECK_LIBRARY(rrd, rrd_create, [ PHP_ADD_LIBRARY_WITH_PATH(rrd, $RRDTOOL_LIBDIR, RRD_SHARED_LIBADD) AC_DEFINE(HAVE_RRDTOOL, 1, [ ]) ], [ AC_MSG_ERROR([wrong rrd lib version or lib not found]) ], [ -L$RRDTOOL_LIBDIR ]) dnl save temporary LDFLAGS, necessary for PHP_CHECK_FUNC old_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS -L$RRDTOOL_LIBDIR" dnl rrd_graph_v is available in 1.3.0+ PHP_CHECK_FUNC(rrd_graph_v, rrd) if test "$ac_cv_func_rrd_graph_v" != yes; then AC_MSG_ERROR([rrd lib version seems older than 1.3.0, update to 1.3.0+]) fi dnl rrd_lastupdate_r available in 1.4.0+ PHP_CHECK_FUNC(rrd_lastupdate_r, rrd) dnl rrdc_disconnect available in 1.4.0+ PHP_CHECK_FUNC(rrdc_disconnect, rrd) LDFLAGS=$old_LDFLAGS PHP_NEW_EXTENSION(rrd, rrd.c rrd_graph.c rrd_create.c rrd_update.c rrd_info.c, $ext_shared) PHP_SUBST(RRD_SHARED_LIBADD) fi php-rrd-1.1.3/rrd-1.1.3/php_rrd.h000066400000000000000000000016241226725740500161410ustar00rootroot00000000000000/** * PHP bindings to the rrdtool * * This source file is subject to the BSD license that is bundled * with this package in the file LICENSE. * --------------------------------------------------------------- * Author: Miroslav Kubelik * --------------------------------------------------------------- */ #ifndef PHP_RRD_H #define PHP_RRD_H extern zend_module_entry rrd_module_entry; #define phpext_rrd_ptr &rrd_module_entry #define PHP_RRD_VERSION "1.1.3" #ifdef ZTS #include "TSRM.h" #endif #ifndef zend_parse_parameters_none # define zend_parse_parameters_none() zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") #endif typedef struct _rrd_args { int count; char **args; } rrd_args; extern rrd_args *rrd_args_init_by_phparray(const char *command_name, const char *filename, const zval *options TSRMLS_DC); extern void rrd_args_free(rrd_args *args); #endif /* PHP_RRD_H */ php-rrd-1.1.3/rrd-1.1.3/rrd.c000066400000000000000000000427541226725740500152760ustar00rootroot00000000000000/** * PHP bindings to the rrdtool * * This source file is subject to the BSD license that is bundled * with this package in the file LICENSE. * --------------------------------------------------------------- * Author: Miroslav Kubelik * --------------------------------------------------------------- */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "ext/standard/php_smart_str.h" #include "ext/standard/php_array.h" #include "ext/standard/info.h" #include #include "php_rrd.h" #include "rrd_graph.h" #include "rrd_create.h" #include "rrd_update.h" #include "rrd_info.h" /* {{{ proto string rrd_error() Get the error message set by the last rrd tool function call, this function clear error buffer also. */ PHP_FUNCTION(rrd_error) { if (zend_parse_parameters_none() == FAILURE) { return; } if (!rrd_test_error()) RETURN_FALSE; RETVAL_STRING(rrd_get_error(), 1); rrd_clear_error(); } /* }}} */ /* {{{ proto array rrd_fetch(string file, array options) Fetch data from RRD in requested resolution. */ PHP_FUNCTION(rrd_fetch) { char *filename; int filename_length; zval *zv_arr_options; rrd_args *argv; /* returned values if rrd_fetch doesn't fail */ time_t start, end; ulong step, ds_cnt; /* count of data sources */ char **ds_namv; /* list of data source names */ rrd_value_t *ds_data; /* all data from all sources */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa", &filename, &filename_length, &zv_arr_options) == FAILURE) { return; } if (php_check_open_basedir(filename TSRMLS_CC)) RETURN_FALSE; argv = rrd_args_init_by_phparray("fetch", filename, zv_arr_options TSRMLS_CC); if (!argv) { zend_error(E_WARNING, "cannot allocate arguments options"); RETURN_FALSE; } if (rrd_test_error()) rrd_clear_error(); /* call rrd_fetch and test if fails */ if (rrd_fetch(argv->count-1, &argv->args[1], &start, &end, &step, &ds_cnt, &ds_namv, &ds_data) == -1 ) { rrd_args_free(argv); RETURN_FALSE; } /* making return array*/ array_init(return_value); add_assoc_long(return_value, "start", start); add_assoc_long(return_value, "end", end); add_assoc_long(return_value, "step", step); /* add "ds_namv" and "data" array into return values if there is any * result data */ if (!ds_data || !ds_namv || !ds_cnt) { add_assoc_null(return_value, "data"); } else { rrd_value_t *datap = ds_data; uint timestamp, ds_counter; /* final array for all data from all data sources */ zval *zv_data_array; MAKE_STD_ZVAL(zv_data_array) array_init(zv_data_array); /* add arrays for each data source, each array will be filled with * retrieved data for a particular data source */ for (ds_counter = 0; ds_counter < ds_cnt; ds_counter++) { zval *zv_ds_data_array; MAKE_STD_ZVAL(zv_ds_data_array) array_init(zv_ds_data_array); add_assoc_zval(zv_data_array, ds_namv[ds_counter], zv_ds_data_array); } for (timestamp = start + step; timestamp <= end; timestamp += step) { /* try to find current data source result array in the * zv_data_array */ zend_hash_internal_pointer_reset(Z_ARRVAL_P(zv_data_array)); for (ds_counter = 0; ds_counter < ds_cnt; ds_counter++) { /* pointer for one data source retrieved data */ zval **ds_data_array; /* value for key (timestamp) in data array */ zval *zv_timestamp; MAKE_STD_ZVAL(zv_timestamp); ZVAL_LONG(zv_timestamp, timestamp); convert_to_string(zv_timestamp); /* gets pointer for data source result array */ zend_hash_get_current_data(Z_ARRVAL_P(zv_data_array), (void**) &ds_data_array); add_assoc_double(*ds_data_array, Z_STRVAL_P(zv_timestamp), *(datap++)); zend_hash_move_forward(Z_ARRVAL_P(zv_data_array)); zval_dtor(zv_timestamp); efree(zv_timestamp); } } add_assoc_zval(return_value, "data", zv_data_array); /* free data from rrd_fetch */ free(ds_data); for (ds_counter = 0; ds_counter < ds_cnt; ds_counter++) { free(ds_namv[ds_counter]); } free(ds_namv); } rrd_args_free(argv); } /* }}} */ /* {{{ proto int rrd_first(string file [, int rraindex = 0]) Gets first update time of an RRD file */ PHP_FUNCTION(rrd_first) { char *filename; int filename_length; long rraindex = 0; /* return value from rrd_first_r call */ time_t rrd_first_return_val; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_length, &rraindex) == FAILURE) { return; } if (rraindex < 0) { rrd_set_error("invalid rraindex number, rraindex must be >= 0"); RETURN_FALSE; } if (php_check_open_basedir(filename TSRMLS_CC)) RETURN_FALSE; if (rrd_test_error()) rrd_clear_error(); /* call rrd_first and test if fails */ rrd_first_return_val = rrd_first_r(filename, rraindex); if (rrd_first_return_val == -1) { RETURN_FALSE; } RETURN_LONG(rrd_first_return_val); } /* }}} */ /* {{{ proto int rrd_last(string file) Gets last update time of an RRD file */ PHP_FUNCTION(rrd_last) { char *filename; int filename_length; /* return value from rrd_first_r call */ time_t rrd_last_return_val; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_length) == FAILURE) { return; } if (php_check_open_basedir(filename TSRMLS_CC)) RETURN_FALSE; if (rrd_test_error()) rrd_clear_error(); /* call rrd_last and test if fails */ rrd_last_return_val = rrd_last_r(filename); if (rrd_last_return_val == -1) { RETURN_FALSE; } RETURN_LONG(rrd_last_return_val); } /* }}} */ /* {{{ proto int rrd_lastupdate(string file) Gets last update details of an RRD file */ PHP_FUNCTION(rrd_lastupdate) { char *filename; int filename_length; /* list of arguments for rrd_lastupdate call, it's more efficient then * usage of rrd_args, because there isn't array of arguments in parameters */ char *argv[3]; /* return values from rrd_lastupdate_r function */ time_t last_update; unsigned long ds_cnt; char **ds_namv; char **last_ds; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_length) == FAILURE) { return; } if (php_check_open_basedir(filename TSRMLS_CC)) RETURN_FALSE; argv[0] = "dummy"; argv[1] = estrdup("lastupdate"); argv[2] = estrndup(filename, filename_length); if (rrd_test_error()) rrd_clear_error(); #ifdef HAVE_RRD_LASTUPDATE_R if (rrd_lastupdate_r(argv[2], &last_update, &ds_cnt, &ds_namv, &last_ds) == -1) { #else if (rrd_lastupdate(2, &argv[1], &last_update, &ds_cnt, &ds_namv, &last_ds) == -1) { #endif efree(argv[2]); efree(argv[1]); RETURN_FALSE; } efree(argv[2]); efree(argv[1]); /* making return array*/ array_init(return_value); add_assoc_long(return_value, "last_update", last_update); add_assoc_long(return_value, "ds_cnt", ds_cnt); /* "ds_navm" return array or null, if no available */ if (!ds_namv || !ds_cnt) { add_assoc_null(return_value, "ds_namv"); } else { uint i; zval *zv_ds_namv_array; MAKE_STD_ZVAL(zv_ds_namv_array); array_init(zv_ds_namv_array); for (i = 0; i < ds_cnt; i++) { add_next_index_string(zv_ds_namv_array, ds_namv[i], 1); free(ds_namv[i]); } free(ds_namv); add_assoc_zval(return_value, "ds_navm", zv_ds_namv_array); } /* "data" return array or null, if no available */ if (!last_ds || !ds_cnt) { add_assoc_null(return_value, "data"); } else { uint i; zval *zv_data_array; MAKE_STD_ZVAL(zv_data_array); array_init(zv_data_array); /* simple array for "data" is enough, data source names and timestamps are * available under other return value keys */ for (i = 0; i < ds_cnt; i++) { add_next_index_string(zv_data_array, last_ds[i], 1); free(last_ds[i]); } free(last_ds); add_assoc_zval(return_value, "data", zv_data_array); } } /* {{{ proto array rrd_restore(string xmlFile, string rrdFile [, array options]) Restores an RRD file from a XML dump */ PHP_FUNCTION(rrd_restore) { char *xml_filename, *rrd_filename; int xml_filename_length, rrd_filename_length; zval *zv_arr_options = NULL; /* this is merge of options and rrd_filename. This is needed because * rrd_args_init_by_phparray allows only one filename as argument, so * rrd_filename mugst be part of array of arguments */ zval *zv_options; rrd_args *argv; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a", &xml_filename, &xml_filename_length, &rrd_filename, &rrd_filename_length, &zv_arr_options) == FAILURE) { return; } if (php_check_open_basedir(xml_filename TSRMLS_CC)) RETURN_FALSE; if (php_check_open_basedir(rrd_filename TSRMLS_CC)) RETURN_FALSE; /* zv_options = merge rrd_filename and zv_arr_options content */ MAKE_STD_ZVAL(zv_options); array_init(zv_options); add_next_index_string(zv_options, rrd_filename, 1); if (zv_arr_options && Z_TYPE_P(zv_arr_options) == IS_ARRAY) { php_array_merge(Z_ARRVAL_P(zv_options), Z_ARRVAL_P(zv_arr_options), 0 TSRMLS_CC); } argv = rrd_args_init_by_phparray("restore", xml_filename, zv_options TSRMLS_CC); if (!argv) { zend_error(E_WARNING, "cannot allocate arguments options"); RETURN_FALSE; } if (rrd_test_error()) rrd_clear_error(); /* call rrd_ restore and test if fails */ if (rrd_restore(argv->count-1, &argv->args[1]) == -1) { RETVAL_FALSE; } else { RETVAL_TRUE; } zval_dtor(zv_options); rrd_args_free(argv); } /* }}} */ /* {{{ proto bool rrd_tune(string file, array options) Tune an RRD file with the options passed (passed via array) */ PHP_FUNCTION(rrd_tune) { char *filename; int filename_length; zval *zv_arr_options; rrd_args *argv; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa", &filename, &filename_length, &zv_arr_options) == FAILURE) { return; } if (!zend_hash_num_elements(Z_ARRVAL_P(zv_arr_options))) { zend_error(E_WARNING, "options array mustn't be empty"); RETURN_FALSE; } if (php_check_open_basedir(filename TSRMLS_CC)) RETURN_FALSE; argv = rrd_args_init_by_phparray("tune", filename, zv_arr_options TSRMLS_CC); if (!argv) { zend_error(E_WARNING, "cannot allocate arguments options"); RETURN_FALSE; } if (rrd_test_error()) rrd_clear_error(); /* call rrd_tune and test if fails */ if (rrd_tune(argv->count-1, &argv->args[1]) == -1 ) { RETVAL_FALSE; } else { RETVAL_TRUE; } rrd_args_free(argv); } /* }}} */ /* {{{ proto array rrd_xport(array options) * Creates a graph based on options passed via an array */ PHP_FUNCTION(rrd_xport) { zval *zv_arr_options; rrd_args *argv; /* return values from rrd_xport */ int xxsize; time_t start, end, time_index; ulong step, outvar_count; char **legend_v; rrd_value_t *data, *data_ptr; zval *zv_data; ulong outvar_index; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &zv_arr_options) == FAILURE) { return; } argv = rrd_args_init_by_phparray("xport", "", zv_arr_options TSRMLS_CC); if (!argv) { zend_error(E_WARNING, "cannot allocate arguments options"); RETURN_FALSE; } if (rrd_test_error()) rrd_clear_error(); /* call rrd_xport and test if fails */ if (rrd_xport(argv->count-1, &argv->args[1], &xxsize, &start, &end, &step, &outvar_count, &legend_v, &data) == -1) { php_printf("rrd_xport failed"); rrd_args_free(argv); RETURN_FALSE; } rrd_args_free(argv); /* fill rrd_xport return values into array */ array_init(return_value); add_assoc_long(return_value, "start", start + step); add_assoc_long(return_value, "end", end); add_assoc_long(return_value, "step", step); /* no data available */ if (!data) { add_assoc_null(return_value, "data"); return; } MAKE_STD_ZVAL(zv_data); array_init(zv_data); for (outvar_index = 0; outvar_index < outvar_count; outvar_index++) { /* array for a whole one output variable data, it contains indexes * array( * "legend" => "variable legend", * "data" => array( * 920807400 => 0.14, * 920807800 => 21, * ... * )) */ zval *zv_var_data, *time_data; MAKE_STD_ZVAL(zv_var_data); array_init(zv_var_data); MAKE_STD_ZVAL(time_data); array_init(time_data); add_assoc_string(zv_var_data, "legend", legend_v[outvar_index], 1); free(legend_v[outvar_index]); data_ptr = data + outvar_index; for (time_index = start+step; time_index <= end; time_index += step) { /* value for key (timestamp) in data array */ zval *zv_timestamp; MAKE_STD_ZVAL(zv_timestamp); ZVAL_LONG(zv_timestamp, time_index); convert_to_string(zv_timestamp); add_assoc_double(time_data, Z_STRVAL_P(zv_timestamp), *data_ptr); data_ptr += outvar_count; zval_dtor(zv_timestamp); } add_assoc_zval(zv_var_data, "data", time_data); add_next_index_zval(zv_data, zv_var_data); } add_assoc_zval(return_value, "data", zv_data); free(legend_v); free(data); } /* }}} */ #ifdef HAVE_RRDC_DISCONNECT /* {{{ proto void rrdc_disconnect() * Close any outstanding connection to rrd cache daemon. */ PHP_FUNCTION(rrdc_disconnect) { if (zend_parse_parameters_none() == FAILURE) { return; } rrdc_disconnect(); } #endif /* {{{ proto string rrd_version() * Gets version of underlying librrd. */ PHP_FUNCTION(rrd_version) { if (zend_parse_parameters_none() == FAILURE) { return; } RETVAL_STRING(rrd_strversion(), 1); } /* {{{ arguments */ ZEND_BEGIN_ARG_INFO(arginfo_rrd_fetch, 0) ZEND_ARG_INFO(0, file) ZEND_ARG_INFO(0, options) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_rrd_first, 0, 0, 1) ZEND_ARG_INFO(0, file) ZEND_ARG_INFO(0, raaindex) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_rrd_last, 0) ZEND_ARG_INFO(0, file) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_rrd_lastupdate, 0) ZEND_ARG_INFO(0, file) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_rrd_restore, 0, 0, 2) ZEND_ARG_INFO(0, xml_file) ZEND_ARG_INFO(0, rrd_file) ZEND_ARG_INFO(0, options) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_rrd_tune, 0) ZEND_ARG_INFO(0, file) ZEND_ARG_INFO(0, options) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_rrd_xport, 0) ZEND_ARG_INFO(0, options) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_rrd_info, 0) ZEND_ARG_INFO(0, file) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_rrd_graph, 0) ZEND_ARG_INFO(0, file) ZEND_ARG_INFO(0, options) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_rrd_create, 0) ZEND_ARG_INFO(0, filename) ZEND_ARG_INFO(0, options) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_rrd_update, 0) ZEND_ARG_INFO(0, file) ZEND_ARG_INFO(0, options) ZEND_END_ARG_INFO() /* }}} */ /* {{{ */ static zend_function_entry rrd_functions[] = { PHP_FE(rrd_update, arginfo_rrd_update) PHP_FE(rrd_create, arginfo_rrd_create) PHP_FE(rrd_graph, arginfo_rrd_graph) PHP_FE(rrd_error, NULL) PHP_FE(rrd_fetch, arginfo_rrd_fetch) PHP_FE(rrd_first, arginfo_rrd_first) PHP_FE(rrd_info, arginfo_rrd_info) PHP_FE(rrd_last, arginfo_rrd_last) PHP_FE(rrd_lastupdate, arginfo_rrd_lastupdate) PHP_FE(rrd_restore, arginfo_rrd_restore) PHP_FE(rrd_tune, arginfo_rrd_tune) PHP_FE(rrd_xport, arginfo_rrd_xport) #ifdef HAVE_RRDC_DISCONNECT PHP_FE(rrdc_disconnect, NULL) #endif PHP_FE(rrd_version, NULL) {NULL, NULL, NULL} }; /* }}} */ #ifdef COMPILE_DL_RRD ZEND_GET_MODULE(rrd) #endif /* {{{ PHP_MINIT_FUNCTION */ static PHP_MINIT_FUNCTION(rrd) { rrd_graph_minit(TSRMLS_C); rrd_create_minit(TSRMLS_C); rrd_update_minit(TSRMLS_C); return SUCCESS; } /* }}} */ /* {{{ PHP_MINFO_FUNCTION */ static PHP_MINFO_FUNCTION(rrd) { php_info_print_table_start(); php_info_print_table_header(2, "rrd tool module", "enabled"); php_info_print_table_row(2, "rrd tool module version", PHP_RRD_VERSION); php_info_print_table_row(2, "rrdtool library version", rrd_strversion()); php_info_print_table_end(); } /* }}} */ /* {{{ PHP_MSHUTDOWN_FUNCTION */ static PHP_MSHUTDOWN_FUNCTION(rrd) { #ifdef HAVE_RRDC_DISCONNECT /* ensure that any connection to rrd cache deamon will be closed */ rrdc_disconnect(); #endif return SUCCESS; } /* }}} */ /* {{{ rrd module_entry */ zend_module_entry rrd_module_entry = { STANDARD_MODULE_HEADER, "rrd", rrd_functions, PHP_MINIT(rrd), PHP_MSHUTDOWN(rrd), NULL, /* PHP_RINIT(rrd) */ NULL, /* PHP_RSHUTDOWN(rrd) */ PHP_MINFO(rrd), PHP_RRD_VERSION, STANDARD_MODULE_PROPERTIES }; /* }}} */ /* {{{ Inits rrd arguments object for a particular rrd command by php array * filename paremeter is optional. */ rrd_args *rrd_args_init_by_phparray(const char *command_name, const char *filename, const zval *options TSRMLS_DC) { uint i, option_count, args_counter = 2; if (Z_TYPE_P(options) != IS_ARRAY) return NULL; option_count = zend_hash_num_elements(Z_ARRVAL_P(options)); if (!option_count) return NULL; if (!strlen(command_name)) return NULL; rrd_args *result = (rrd_args *)emalloc(sizeof(rrd_args)); /* "dummy" + command_name + filename if presented */ result->count = option_count + (strlen(filename) ? 3 : 2); result->args = (char **)safe_emalloc(result->count, sizeof(char *), 0); /* "dummy" and command_name are always needed */ result->args[0] = "dummy"; result->args[1] = estrdup(command_name); /* append filename if it's presented */ if (strlen(filename)) result->args[args_counter++] = estrdup(filename); zend_hash_internal_pointer_reset(Z_ARRVAL_P(options)); for (i=0; iargs[args_counter++] = estrdup(option.c); smart_str_free(&option); zend_hash_move_forward(Z_ARRVAL_P(options)); } return result; } /* }}} */ /* {{{ Frees all memory for arguments object */ void rrd_args_free(rrd_args *args) { int i; if (!args || !args->args) return; for (i=1; icount; i++) efree(args->args[i]); efree(args->args); efree(args); } /* }}} */ php-rrd-1.1.3/rrd-1.1.3/rrd_create.c000066400000000000000000000241331226725740500166100ustar00rootroot00000000000000/** * PHP bindings to the rrdtool * * This source file is subject to the BSD license that is bundled * with this package in the file LICENSE. * --------------------------------------------------------------- * Author: Miroslav Kubelik * --------------------------------------------------------------- */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "php.h" #include "rrd_create.h" #include "php_rrd.h" #include "zend_exceptions.h" #include "ext/standard/php_array.h" /* declare class entry */ static zend_class_entry *ce_rrd_create; /* declare class handlers */ static zend_object_handlers rrd_create_handlers; /* overloading the standard zend object structure (std property) in the need of having dedicated creating/cloning/destruction functions */ typedef struct _rrd_create_object { zend_object std; /** path to newly created rrd file */ char *file_path; /* "--start" parameters in rrd create */ char *start_time; /* "--step" parameters in rrd create */ zval *zv_step; /* "DS" parameters in rrd create */ zval *zv_arr_data_sources; /* "RRA" parameters in rrd create */ zval *zv_arr_archives; } rrd_create_object; /* {{{ rrd_create_object_dtor close all resources and the memory allocated for our internal object */ static void rrd_create_object_dtor(void *object TSRMLS_DC) { rrd_create_object *intern_obj = (rrd_create_object *)object; if (intern_obj->file_path) efree(intern_obj->file_path); if (intern_obj->start_time) efree(intern_obj->start_time); if (intern_obj->zv_step) zval_dtor(intern_obj->zv_step); if (intern_obj->zv_arr_data_sources) zval_dtor(intern_obj->zv_arr_data_sources); if (intern_obj->zv_arr_archives) zval_dtor(intern_obj->zv_arr_archives); zend_object_std_dtor(&intern_obj->std TSRMLS_CC); efree(intern_obj); } /* }}} */ /* {{{ rrd_create_object_new creates new rrd create object */ static zend_object_value rrd_create_object_new(zend_class_entry *ce TSRMLS_DC) { rrd_create_object *intern_obj; zend_object_value retval; #if ZEND_MODULE_API_NO < 20100409 zval *tmp; #endif intern_obj = ecalloc(1, sizeof(*intern_obj)); zend_object_std_init(&intern_obj->std, ce TSRMLS_CC); intern_obj->file_path = NULL; intern_obj->start_time = NULL; intern_obj->zv_step = NULL; intern_obj->zv_arr_data_sources = NULL; intern_obj->zv_arr_archives = NULL; #if ZEND_MODULE_API_NO >= 20100409 object_properties_init(&intern_obj->std, ce); #else zend_hash_copy(intern_obj->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval*) ); #endif retval.handle = zend_objects_store_put(intern_obj, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)rrd_create_object_dtor, NULL TSRMLS_CC ); retval.handlers = &rrd_create_handlers; return retval; } /* }}} */ /* {{{ proto void RRDCreator::__construct(string path [,string startTime] [,int step]) creates new object for creating rrd database */ PHP_METHOD(RRDCreator, __construct) { rrd_create_object *intern_obj; char *path; int path_length; /* better to set defaults for optional parameters */ char *start_time = NULL; int start_time_length = 0; long step = 0; int argc = ZEND_NUM_ARGS(); if (zend_parse_parameters(argc TSRMLS_CC, "s|sl", &path, &path_length, &start_time, &start_time_length, &step) == FAILURE) { return; } if (path_length == 0) { zend_throw_exception(zend_exception_get_default(TSRMLS_C), "path for rrd file cannot be empty string", 0 TSRMLS_CC); return; } if (argc > 1 && start_time_length == 0) { zend_throw_exception(zend_exception_get_default(TSRMLS_C), "startTime cannot be empty string", 0 TSRMLS_CC); return; } if (argc > 2 && step <= 0) { zend_throw_exception(zend_exception_get_default(TSRMLS_C), "step parameter must be greater then 0", 0 TSRMLS_CC); return; } intern_obj = (rrd_create_object*)zend_object_store_get_object(getThis() TSRMLS_CC); intern_obj->file_path = estrdup(path); if (start_time) intern_obj->start_time = estrdup(start_time); if (step) { MAKE_STD_ZVAL(intern_obj->zv_step); ZVAL_LONG(intern_obj->zv_step,step); } } /* }}} */ /* {{{ proto RRDCreator::addDataSource(string description) Add information about data source */ PHP_METHOD(RRDCreator, addDataSource) { rrd_create_object *intern_obj; char *desc, *rrd_source_desc; int desc_length; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &desc, &desc_length) == FAILURE) { return; } if (desc_length == 0) { zend_throw_exception(zend_exception_get_default(TSRMLS_C), "description parameter cannot be empty string", 0 TSRMLS_CC); return; } intern_obj = (rrd_create_object*)zend_object_store_get_object(getThis() TSRMLS_CC); if (!intern_obj->zv_arr_data_sources) { MAKE_STD_ZVAL(intern_obj->zv_arr_data_sources); array_init(intern_obj->zv_arr_data_sources); } rrd_source_desc = emalloc(desc_length + 4); strcpy(rrd_source_desc, "DS:"); strcat(rrd_source_desc, desc); add_next_index_string(intern_obj->zv_arr_data_sources, rrd_source_desc, 1); efree(rrd_source_desc); } /* }}} */ /* {{{ proto RRDCreator::addArchive(string description) Add information about new round robin archive */ PHP_METHOD(RRDCreator, addArchive) { rrd_create_object *intern_obj; char *desc, *rrd_archive_desc; int desc_length; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &desc, &desc_length) == FAILURE) { return; } if (desc_length == 0) { zend_throw_exception(zend_exception_get_default(TSRMLS_C), "description parameter cannot be empty string", 0 TSRMLS_CC); return; } intern_obj = (rrd_create_object*)zend_object_store_get_object(getThis() TSRMLS_CC); if (!intern_obj->zv_arr_archives) { MAKE_STD_ZVAL(intern_obj->zv_arr_archives); array_init(intern_obj->zv_arr_archives); } rrd_archive_desc = emalloc(desc_length + 5); strcpy(rrd_archive_desc, "RRA:"); strcat(rrd_archive_desc, desc); add_next_index_string(intern_obj->zv_arr_archives, rrd_archive_desc, 1); efree(rrd_archive_desc); } /* }}} */ /* {{{ proto bool RRDCreator::save() Saves new rrd database according to current properties. */ PHP_METHOD(RRDCreator, save) { rrd_create_object *intern_obj = (rrd_create_object *)zend_object_store_get_object(getThis() TSRMLS_CC); /* help structures for preparing arguments for rrd_create call */ zval *zv_create_argv; rrd_args *create_argv; MAKE_STD_ZVAL(zv_create_argv); array_init(zv_create_argv); if (intern_obj->start_time) { const char *prefix = "--start="; char *start_time_str = emalloc(strlen(intern_obj->start_time) + strlen(prefix) + 1); strcpy(start_time_str, prefix); strcat(start_time_str, intern_obj->start_time); add_next_index_string(zv_create_argv, start_time_str, 1); efree(start_time_str); } if (intern_obj->zv_step) { const char *prefix = "--step="; char *start_time_str; convert_to_string(intern_obj->zv_step); start_time_str = emalloc(strlen(prefix) + Z_STRLEN_P(intern_obj->zv_step) + 1); strcpy(start_time_str, prefix); strcat(start_time_str, Z_STRVAL_P(intern_obj->zv_step)); add_next_index_string(zv_create_argv, start_time_str, 1); /* back to long, doesn't needed, but we are consistent */ convert_to_long(intern_obj->zv_step); efree(start_time_str); } /* add array of archive and data source strings into argument list */ php_array_merge(Z_ARRVAL_P(zv_create_argv), Z_ARRVAL_P(intern_obj->zv_arr_data_sources), 0 TSRMLS_CC); php_array_merge(Z_ARRVAL_P(zv_create_argv), Z_ARRVAL_P(intern_obj->zv_arr_archives), 0 TSRMLS_CC); create_argv = rrd_args_init_by_phparray("create", intern_obj->file_path, zv_create_argv TSRMLS_CC); if (!create_argv) { zend_error(E_WARNING, "cannot allocate arguments options"); zval_dtor(zv_create_argv); RETURN_FALSE; } if (rrd_test_error()) rrd_clear_error(); /* call rrd_create and test if fails */ if (rrd_create(create_argv->count - 1, &create_argv->args[1]) == -1) { zval_dtor(zv_create_argv); rrd_args_free(create_argv); /* throw exception with rrd error string */ zend_throw_exception(zend_exception_get_default(TSRMLS_C), rrd_get_error(), 0 TSRMLS_CC); rrd_clear_error(); return; } zval_dtor(zv_create_argv); rrd_args_free(create_argv); RETURN_TRUE; } /* }}} */ /* {{{ proto bool rrd_create(string file, array options) Create an RRD file with the options passed */ PHP_FUNCTION(rrd_create) { char *filename; int filename_length; zval *zv_arr_options; rrd_args *argv; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa", &filename, &filename_length, &zv_arr_options) == FAILURE) { return; } if (php_check_open_basedir(filename TSRMLS_CC)) RETURN_FALSE; argv = rrd_args_init_by_phparray("create", filename, zv_arr_options TSRMLS_CC); if (!argv) { zend_error(E_WARNING, "cannot allocate arguments options"); RETURN_FALSE; } if (rrd_test_error()) rrd_clear_error(); if (rrd_create(argv->count - 1, &argv->args[1]) == -1 ) { RETVAL_FALSE; } else { RETVAL_TRUE; } rrd_args_free(argv); } /* }}} */ /* Arguments * it's necessary to use unique name e.g. arginfo_rrdcreator_construct because * in PHP < 5.3 ZEND_BEGIN_ARG_INFO_EX doesn't declare arginfo structure as * static */ ZEND_BEGIN_ARG_INFO_EX(arginfo_rrdcreator_construct, 0, 0, 1) ZEND_ARG_INFO(0, path) ZEND_ARG_INFO(0, startTime) ZEND_ARG_INFO(0, step) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_rrdcreator_description, 0, 0, 1) ZEND_ARG_INFO(0, description) ZEND_END_ARG_INFO() /* class method table */ static zend_function_entry rrd_create_methods[] = { PHP_ME(RRDCreator, __construct, arginfo_rrdcreator_construct, ZEND_ACC_PUBLIC) PHP_ME(RRDCreator, save, NULL, ZEND_ACC_PUBLIC) PHP_ME(RRDCreator, addDataSource, arginfo_rrdcreator_description, ZEND_ACC_PUBLIC) PHP_ME(RRDCreator, addArchive, arginfo_rrdcreator_description, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* minit hook, called from main module minit */ void rrd_create_minit(TSRMLS_D) { zend_class_entry ce; INIT_CLASS_ENTRY(ce, "RRDCreator", rrd_create_methods); ce.create_object = rrd_create_object_new; ce_rrd_create = zend_register_internal_class(&ce TSRMLS_CC); memcpy(&rrd_create_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); rrd_create_handlers.clone_obj = NULL; } php-rrd-1.1.3/rrd-1.1.3/rrd_create.h000066400000000000000000000007151226725740500166150ustar00rootroot00000000000000/** * PHP bindings to the rrdtool * * This source file is subject to the BSD license that is bundled * with this package in the file LICENSE. * --------------------------------------------------------------- * Author: Miroslav Kubelik * --------------------------------------------------------------- */ #ifndef RRD_CREATE_H #define RRD_CREATE_H void rrd_create_minit(TSRMLS_D); PHP_FUNCTION(rrd_create); #endif /* RRD_CREATE_H */ php-rrd-1.1.3/rrd-1.1.3/rrd_graph.c000066400000000000000000000262631226725740500164540ustar00rootroot00000000000000/** * PHP bindings to the rrdtool * * This source file is subject to the BSD license that is bundled * with this package in the file LICENSE. * --------------------------------------------------------------- * Author: Miroslav Kubelik * --------------------------------------------------------------- */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "zend_exceptions.h" #include "ext/standard/php_smart_str.h" #include #include "php_rrd.h" #include "rrd_info.h" #include "rrd_graph.h" /* declare class entry */ static zend_class_entry *ce_rrd_graph; /* declare class handlers */ static zend_object_handlers rrd_graph_handlers; /** * overloading the standard zend object structure (std property) in the need * of having dedicated creating/cloning/destruction functions */ typedef struct _rrd_graph_object { zend_object std; char *file_path; zval *zv_arr_options; } rrd_graph_object; /* {{{ rrd_graph_object_dtor close all resources and the memory allocated for our internal object */ static void rrd_graph_object_dtor(void *object TSRMLS_DC) { rrd_graph_object *intern_obj = (rrd_graph_object *)object; if (intern_obj->file_path) efree(intern_obj->file_path); if (intern_obj->zv_arr_options) { zval_dtor(intern_obj->zv_arr_options); } zend_object_std_dtor(&intern_obj->std TSRMLS_CC); efree(intern_obj); } /* }}} */ /* {{{ rrd_graph_object_new creates new rrd graph object */ static zend_object_value rrd_graph_object_new(zend_class_entry *ce TSRMLS_DC) { rrd_graph_object *intern_obj; zend_object_value retval; #if ZEND_MODULE_API_NO < 20100409 zval *tmp; #endif intern_obj = ecalloc(1, sizeof(*intern_obj)); zend_object_std_init(&intern_obj->std, ce TSRMLS_CC); intern_obj->file_path = NULL; intern_obj->zv_arr_options = NULL; #if ZEND_MODULE_API_NO >= 20100409 object_properties_init(&intern_obj->std, ce); #else zend_hash_copy(intern_obj->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval*) ); #endif retval.handle = zend_objects_store_put(intern_obj, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)rrd_graph_object_dtor, NULL TSRMLS_CC ); retval.handlers = &rrd_graph_handlers; return retval; } /* }}} */ /* {{{ proto void RRDGraph::__construct(string path) creates new object for rrd graph function */ PHP_METHOD(RRDGraph, __construct) { rrd_graph_object *intern_obj; char *path; int path_length; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &path_length) == FAILURE) { return; } intern_obj = (rrd_graph_object*)zend_object_store_get_object(getThis() TSRMLS_CC); intern_obj->file_path = estrdup(path); } /* }}} */ /* {{{ proto void RRDGraph::setOptions(array options) set command options for rrd graph call */ PHP_METHOD(RRDGraph, setOptions) { rrd_graph_object *intern_obj; zval *zv_arr_options; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &zv_arr_options) == FAILURE) { return; } intern_obj = (rrd_graph_object*)zend_object_store_get_object(getThis() TSRMLS_CC); /* if our array is initialized, so delete it first */ if (intern_obj->zv_arr_options) { zval_dtor(intern_obj->zv_arr_options); } /* copy array from parameter */ MAKE_STD_ZVAL(intern_obj->zv_arr_options); *intern_obj->zv_arr_options = *zv_arr_options; zval_copy_ctor(intern_obj->zv_arr_options); } /* }}} */ /* {{{ creates arguments for rrd_graph call for RRDGraph instance options */ static rrd_args *rrd_graph_obj_create_argv(const char *command_name, const rrd_graph_object *obj TSRMLS_DC) { /* iterated item */ zval **zv_option_val; /* arguments for rrd_graph call as php array - temporary storage */ zval *zv_argv; rrd_args *result; MAKE_STD_ZVAL(zv_argv); array_init(zv_argv); zend_hash_internal_pointer_reset(Z_ARRVAL_P(obj->zv_arr_options)); while (zend_hash_get_current_data(Z_ARRVAL_P(obj->zv_arr_options), (void**)&zv_option_val) == SUCCESS) { /* copy for converted non-string value, because we don't want to modify * original array item */ zval option_str_copy; /* pointer for current value, either on zv_option_val (current array item) * or on option_str_copy (string converted item) */ zval *option_ptr = *zv_option_val; char *str_key; ulong num_key; smart_str option = {0}; /* one argument option */ /* option with string key means long option, hence they are used as * "key=value" e.g. "--start=920804400" */ if (zend_hash_get_current_key(Z_ARRVAL_P(obj->zv_arr_options), &str_key, &num_key, 0) == HASH_KEY_IS_STRING) { smart_str_appends(&option, str_key); smart_str_appendc(&option, '='); }; /* if option isn't string, use new value as old one casted to string */ if (Z_TYPE_PP(zv_option_val) != IS_STRING) { option_str_copy = **zv_option_val; zval_copy_ctor(&option_str_copy); convert_to_string(&option_str_copy); option_ptr = &option_str_copy; } smart_str_appendl(&option, Z_STRVAL_P(option_ptr), Z_STRLEN_P(option_ptr)); smart_str_0(&option); add_next_index_string(zv_argv, option.c, 1); smart_str_free(&option); if (option_ptr != *zv_option_val) { zval_dtor(&option_str_copy); } zend_hash_move_forward(Z_ARRVAL_P(obj->zv_arr_options)); } result = rrd_args_init_by_phparray(command_name, obj->file_path, zv_argv TSRMLS_CC); zval_dtor(zv_argv); return result; } /* }}} */ /* {{{ proto array RRDGraph::save() Saves graph according to current option */ PHP_METHOD(RRDGraph, save) { rrd_graph_object *intern_obj = (rrd_graph_object *)zend_object_store_get_object(getThis() TSRMLS_CC); /* returned values if rrd_graph doesn't fail */ int xsize, ysize; double ymin,ymax; char **calcpr; /* arguments for rrd_graph call */ rrd_args *graph_argv; if (!intern_obj->zv_arr_options || Z_TYPE_P(intern_obj->zv_arr_options) != IS_ARRAY) { zend_throw_exception(zend_exception_get_default(TSRMLS_C), "options aren't correctly set", 0 TSRMLS_CC); return; } if (php_check_open_basedir(intern_obj->file_path TSRMLS_CC)) { RETURN_FALSE; } graph_argv = rrd_graph_obj_create_argv("graph", intern_obj TSRMLS_CC); if (!graph_argv) { zend_error(E_WARNING, "cannot allocate arguments options"); RETURN_FALSE; } if (rrd_test_error()) rrd_clear_error(); /* call rrd graph and test if fails */ if (rrd_graph(graph_argv->count - 1, &graph_argv->args[1], &calcpr, &xsize, &ysize, NULL, &ymin, &ymax) == -1) { /* throw exception with rrd error string */ zend_throw_exception(zend_exception_get_default(TSRMLS_C), rrd_get_error(), 0 TSRMLS_CC); rrd_clear_error(); rrd_args_free(graph_argv); return; } /* making return array */ array_init(return_value); add_assoc_long(return_value, "xsize", xsize); add_assoc_long(return_value, "ysize", ysize); /* add calcpr return values under "calcpr" key * * if calcpr isn't presented add PHP NULL value */ if (!calcpr) { add_assoc_null(return_value, "calcpr"); } else { /* calcpr is presented, hence create array for it, and add it to return array */ zval *zv_calcpr_array; MAKE_STD_ZVAL(zv_calcpr_array) array_init(zv_calcpr_array); if (calcpr) { uint i; for (i = 0; calcpr[i]; i++) { add_next_index_string(zv_calcpr_array, calcpr[i], 1); free(calcpr[i]); } free(calcpr); } add_assoc_zval(return_value, "calcpr", zv_calcpr_array); } rrd_args_free(graph_argv); } /* }}} */ /* {{{ proto array RRDGraph::saveVerbose() Saves graph according to current option with return an extra information about saved image. */ PHP_METHOD(RRDGraph, saveVerbose) { rrd_graph_object *intern_obj = (rrd_graph_object *)zend_object_store_get_object(getThis() TSRMLS_CC); /* return value from rrd_graphv */ rrd_info_t *rrd_info_data; /* arguments for rrd_graph call */ rrd_args *graph_argv; if (!intern_obj->zv_arr_options || Z_TYPE_P(intern_obj->zv_arr_options) != IS_ARRAY) { zend_throw_exception(zend_exception_get_default(TSRMLS_C), "options aren't correctly set", 0 TSRMLS_CC); return; } graph_argv = rrd_graph_obj_create_argv("graphv", intern_obj TSRMLS_CC); if (!graph_argv) { zend_error(E_WARNING, "cannot allocate arguments options"); RETURN_FALSE; } if (rrd_test_error()) rrd_clear_error(); /* call rrd graphv and test if fails */ rrd_info_data = rrd_graph_v(graph_argv->count - 1, &graph_argv->args[1]); if (!rrd_info_data) { /* throw exception with rrd error string */ zend_throw_exception(zend_exception_get_default(TSRMLS_C), rrd_get_error(), 0 TSRMLS_CC); rrd_clear_error(); rrd_args_free(graph_argv); return; } /* making return array */ array_init(return_value); rrd_info_toarray(rrd_info_data, return_value TSRMLS_CC); rrd_info_free(rrd_info_data); rrd_args_free(graph_argv); } /* }}} */ /* {{{ proto array rrd_graph(string file, array options) Ceates a graph based on options passed via an array. */ PHP_FUNCTION(rrd_graph) { char *filename; int filename_length; zval *zv_arr_options; rrd_args *argv; /* returned values if rrd_graph doesn't fail */ int xsize, ysize; double ymin,ymax; char **calcpr; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa", &filename, &filename_length, &zv_arr_options) == FAILURE) { return; } if (php_check_open_basedir(filename TSRMLS_CC)) RETURN_FALSE; argv = rrd_args_init_by_phparray("graph", filename, zv_arr_options TSRMLS_CC); if (!argv) { zend_error(E_WARNING, "cannot allocate arguments options"); RETURN_FALSE; } if (rrd_test_error()) rrd_clear_error(); /* call rrd graph and test if fails */ if (rrd_graph(argv->count - 1, &argv->args[1], &calcpr, &xsize, &ysize, NULL, &ymin, &ymax) == -1) { rrd_args_free(argv); RETURN_FALSE; } /* making return array*/ array_init(return_value); add_assoc_long(return_value, "xsize", xsize); add_assoc_long(return_value, "ysize", ysize); /* add calcpr return values under "calcpr" key * * if calcpr isn't presented add PHP NULL value */ if (!calcpr) { add_assoc_null(return_value, "calcpr"); } else { /* calcpr is presented, hence create array for it, and add it to return array */ zval *zv_calcpr_array; MAKE_STD_ZVAL(zv_calcpr_array) array_init(zv_calcpr_array); if (calcpr) { uint i; for (i=0; calcpr[i]; i++) { add_next_index_string(zv_calcpr_array, calcpr[i], 1); free(calcpr[i]); } free(calcpr); } add_assoc_zval(return_value, "calcpr", zv_calcpr_array); } rrd_args_free(argv); } /* }}} */ /* arguments */ ZEND_BEGIN_ARG_INFO_EX(arginfo_rrd_path, 0, 0, 1) ZEND_ARG_INFO(0, path) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_rrd_options, 0, 0, 1) ZEND_ARG_INFO(0, options) ZEND_END_ARG_INFO() /* class method table */ static zend_function_entry rrd_graph_methods[] = { PHP_ME(RRDGraph, __construct, arginfo_rrd_path, ZEND_ACC_PUBLIC) PHP_ME(RRDGraph, save, NULL, ZEND_ACC_PUBLIC) PHP_ME(RRDGraph, saveVerbose, NULL, ZEND_ACC_PUBLIC) PHP_ME(RRDGraph, setOptions, arginfo_rrd_options, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* minit hook, called from main module minit */ void rrd_graph_minit(TSRMLS_D) { zend_class_entry ce; INIT_CLASS_ENTRY(ce, "RRDGraph", rrd_graph_methods); ce.create_object = rrd_graph_object_new; ce_rrd_graph = zend_register_internal_class(&ce TSRMLS_CC); memcpy(&rrd_graph_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); rrd_graph_handlers.clone_obj = NULL; } php-rrd-1.1.3/rrd-1.1.3/rrd_graph.h000066400000000000000000000007261226725740500164550ustar00rootroot00000000000000/** * PHP bindings to the rrdtool * * This source file is subject to the BSD license that is bundled * with this package in the file LICENSE. * --------------------------------------------------------------- * Author: Miroslav Kubelik * --------------------------------------------------------------- */ #ifndef RRD_GRAPH_H #define RRD_GRAPH_H extern void rrd_graph_minit(TSRMLS_D); extern PHP_FUNCTION(rrd_graph); #endif /* RRD_GRAPH_H */ php-rrd-1.1.3/rrd-1.1.3/rrd_info.c000066400000000000000000000043331226725740500163000ustar00rootroot00000000000000/** * PHP bindings to the rrdtool * * This source file is subject to the BSD license that is bundled * with this package in the file LICENSE. * --------------------------------------------------------------- * Author: Miroslav Kubelik * --------------------------------------------------------------- */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include #include "php_rrd.h" #include "rrd_info.h" /* {{{ proto array rrd_info(string file) Gets the header information from an RRD. */ PHP_FUNCTION(rrd_info) { char *filename; int filename_length; /* list of arguments for rrd_info call, it's more efficient then u * usage of rrd_args, because there isn't array of arguments in parameters */ char *argv[3]; /* return value from rrd_info_r() */ rrd_info_t *rrd_info_data; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_length) == FAILURE) { return; } if (php_check_open_basedir(filename TSRMLS_CC)) RETURN_FALSE; argv[0] = "dummy"; argv[1] = estrdup("info"); argv[2] = estrndup(filename, filename_length); rrd_info_data = rrd_info(2, &argv[1]); efree(argv[2]); efree(argv[1]); if (!rrd_info_data) RETURN_FALSE; /* making return array*/ array_init(return_value); rrd_info_toarray(rrd_info_data, return_value TSRMLS_CC); rrd_info_free(rrd_info_data); } /* }}} */ /* {{{ converts rrd_info_t struct into php array @return int 1 OK, 0 conversion failed */ uint rrd_info_toarray(const rrd_info_t *rrd_info_data, zval *array TSRMLS_DC) { const rrd_info_t *data_p; if (!rrd_info_data || Z_TYPE_P(array) != IS_ARRAY) return 0; data_p = rrd_info_data; while (data_p) { switch (data_p->type) { case RD_I_VAL: add_assoc_double(array, data_p->key, data_p->value.u_val); break; case RD_I_CNT: add_assoc_long(array, data_p->key, data_p->value.u_cnt); break; case RD_I_INT: add_assoc_long(array, data_p->key, data_p->value.u_int); break; case RD_I_STR: add_assoc_string(array, data_p->key, data_p->value.u_str, 1); break; case RD_I_BLO: add_assoc_stringl(array, data_p->key, (char *)data_p->value.u_blo.ptr, data_p->value.u_blo.size, 1); break; } data_p = data_p->next; } return 1; } /* }}} */ php-rrd-1.1.3/rrd-1.1.3/rrd_info.h000066400000000000000000000011441226725740500163020ustar00rootroot00000000000000/** * PHP bindings to the rrdtool * * This source file is subject to the BSD license that is bundled * with this package in the file LICENSE. * --------------------------------------------------------------- * Author: Miroslav Kubelik * --------------------------------------------------------------- */ #ifndef RRD_INFO_H #define RRD_INFO_H extern PHP_FUNCTION(rrd_info); /* necessary, because rrd_info_t definition is needed for function definition */ #include extern uint rrd_info_toarray(const rrd_info_t *rrd_info_data, zval *array TSRMLS_DC); #endif /* RRD_INFO_H */ php-rrd-1.1.3/rrd-1.1.3/rrd_update.c000066400000000000000000000173171226725740500166350ustar00rootroot00000000000000/** * PHP bindings to the rrdtool * * This source file is subject to the BSD license that is bundled * with this package in the file LICENSE. * --------------------------------------------------------------- * Author: Miroslav Kubelik * --------------------------------------------------------------- */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "php.h" #include "php_rrd.h" #include "rrd_update.h" #include "zend_exceptions.h" #include "ext/standard/php_smart_str.h" /* declare class entry */ static zend_class_entry *ce_rrd_update; /* declare class handlers */ static zend_object_handlers rrd_update_handlers; /* overloading the standard zend object structure (std property) in the need of having dedicated creating/cloning/destruction functions */ typedef struct _rrd_update_object { zend_object std; /** path to newly created rrd file */ char *file_path; } rrd_update_object; /* {{{ rrd_update_object_dtor close all resources and the memory allocated for our internal object */ static void rrd_update_object_dtor(void *object TSRMLS_DC) { rrd_update_object *intern_obj = (rrd_update_object *)object; if (intern_obj->file_path) efree(intern_obj->file_path); zend_object_std_dtor(&intern_obj->std TSRMLS_CC); efree(intern_obj); } /* }}} */ /* {{{ rrd_update_object_new creates new rrd update object */ static zend_object_value rrd_update_object_new(zend_class_entry *ce TSRMLS_DC) { rrd_update_object *intern_obj; zend_object_value retval; #if ZEND_MODULE_API_NO < 20100409 zval *tmp; #endif intern_obj = ecalloc(1, sizeof(*intern_obj)); zend_object_std_init(&intern_obj->std, ce TSRMLS_CC); intern_obj->file_path = NULL; #if ZEND_MODULE_API_NO >= 20100409 object_properties_init(&intern_obj->std, ce); #else zend_hash_copy(intern_obj->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval*) ); #endif retval.handle = zend_objects_store_put(intern_obj, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)rrd_update_object_dtor, NULL TSRMLS_CC ); retval.handlers = &rrd_update_handlers; return retval; } /* }}} */ /* {{{ proto void RRDUpdater::__construct(string path) creates new object for rrd update function */ PHP_METHOD(RRDUpdater, __construct) { rrd_update_object *intern_obj; char *path; int path_length; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &path_length) == FAILURE) { return; } intern_obj = (rrd_update_object*)zend_object_store_get_object(getThis() TSRMLS_CC); intern_obj->file_path = estrdup(path); } /* }}} */ /* {{{ proto array RRDUpdater::update(array $values, [string time=time()]) Updates data sources in RRD database */ PHP_METHOD(RRDUpdater, update) { rrd_update_object *intern_obj; zval *zv_values_array; /* help structures for preparing arguments for rrd_update call */ zval *zv_update_argv; rrd_args *update_argv; char *time = NULL; int time_str_length = 0; int argc = ZEND_NUM_ARGS(); uint ds_count,i; /* string for all data source names formated for rrd_update call */ smart_str ds_names = {0}; /* string for all data source values for rrd_update call */ smart_str ds_vals = {0}; if (zend_parse_parameters(argc TSRMLS_CC, "a|s", &zv_values_array, &time, &time_str_length) == FAILURE) { return; } ds_count = zend_hash_num_elements(Z_ARRVAL_P(zv_values_array)); if (ds_count<=0) { RETURN_TRUE; } intern_obj = (rrd_update_object *)zend_object_store_get_object(getThis() TSRMLS_CC); if (php_check_open_basedir(intern_obj->file_path TSRMLS_CC)) { RETURN_FALSE; } if (time_str_length == 0) { if (argc > 1) { zend_throw_exception(zend_exception_get_default(TSRMLS_C), "time cannot be empty string", 0 TSRMLS_CC); return; } /* default time string, see rrdtool update man page, it's need to be freed */ time = estrdup("N"); } zend_hash_internal_pointer_reset(Z_ARRVAL_P(zv_values_array)); for (i=0; ifile_path, zv_update_argv TSRMLS_CC); if (!update_argv) { zend_error(E_WARNING, "cannot allocate arguments options"); zval_dtor(zv_update_argv); if (time_str_length == 0) efree(time); RETURN_FALSE; } if (rrd_test_error()) rrd_clear_error(); /* call rrd_update and test if fails */ if (rrd_update(update_argv->count - 1, &update_argv->args[1]) == -1) { zval_dtor(zv_update_argv); rrd_args_free(update_argv); if (time_str_length == 0) efree(time); /* throw exception with rrd error string */ zend_throw_exception(zend_exception_get_default(TSRMLS_C), rrd_get_error(), 0 TSRMLS_CC); rrd_clear_error(); return; } /* parameter isn't presented and we alloced default one, so we need to * free this one */ if (time_str_length == 0) efree(time); zval_dtor(zv_update_argv); rrd_args_free(update_argv); RETURN_TRUE; } /* }}} */ /* {{{ proto int rrd_update(string file, array options) Updates the RRD file with a particular options and values. */ PHP_FUNCTION(rrd_update) { char *filename; int filename_length; zval *zv_arr_options; rrd_args *argv; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa", &filename, &filename_length, &zv_arr_options) == FAILURE) { return; } if (php_check_open_basedir(filename TSRMLS_CC)) RETURN_FALSE; argv = rrd_args_init_by_phparray("update", filename, zv_arr_options TSRMLS_CC); if (!argv) { zend_error(E_WARNING, "cannot allocate arguments options"); RETURN_FALSE; } if (rrd_test_error()) rrd_clear_error(); if (rrd_update(argv->count - 1, &argv->args[1]) == -1 ) { RETVAL_FALSE; } else { RETVAL_TRUE; } rrd_args_free(argv); } /* }}} */ /* Arguments * it's necessary to use unique name e.g. arginfo_rrdcreator_construct because * in PHP < 5.3 ZEND_BEGIN_ARG_INFO_EX doesn't declare arginfo structure as * static */ ZEND_BEGIN_ARG_INFO(arginfo_rrdupdater_construct, 0) ZEND_ARG_INFO(0, path) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_rrdupdater_update, 0, 0, 1) ZEND_ARG_INFO(0, values) ZEND_ARG_INFO(0, time) ZEND_END_ARG_INFO() /* class method table */ static zend_function_entry rrd_update_methods[] = { PHP_ME(RRDUpdater, __construct, arginfo_rrdupdater_construct, ZEND_ACC_PUBLIC) PHP_ME(RRDUpdater, update, arginfo_rrdupdater_update, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* minit hook, called from main module minit */ void rrd_update_minit(TSRMLS_D) { zend_class_entry ce; INIT_CLASS_ENTRY(ce, "RRDUpdater", rrd_update_methods); ce.create_object = rrd_update_object_new; ce_rrd_update = zend_register_internal_class(&ce TSRMLS_CC); memcpy(&rrd_update_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); rrd_update_handlers.clone_obj = NULL; } php-rrd-1.1.3/rrd-1.1.3/rrd_update.h000066400000000000000000000007151226725740500166340ustar00rootroot00000000000000/** * PHP bindings to the rrdtool * * This source file is subject to the BSD license that is bundled * with this package in the file LICENSE. * --------------------------------------------------------------- * Author: Miroslav Kubelik * --------------------------------------------------------------- */ #ifndef RRD_UPDATE_H #define RRD_UPDATE_H void rrd_update_minit(TSRMLS_D); PHP_FUNCTION(rrd_update); #endif /* RRD_UPDATE_H */ php-rrd-1.1.3/rrd-1.1.3/tests/000077500000000000000000000000001226725740500154715ustar00rootroot00000000000000php-rrd-1.1.3/rrd-1.1.3/tests/data/000077500000000000000000000000001226725740500164025ustar00rootroot00000000000000php-rrd-1.1.3/rrd-1.1.3/tests/data/Makefile.in000066400000000000000000000045751226725740500204620ustar00rootroot00000000000000# Makefile for creating data for test # # usage from main extension directory for creating fresh data # make -C tests/data clean # make -C tests/data all # rrd_binary = @RRDTOOL_BIN@ all: speed.png rrd_updater_fetch.txt speed-dump.xml moreDS-empty.rrd moreDS_fetch.txt @echo 'You can run "make test"' clean: rm -f *.rrd *.png *.xml *fetch.txt speed-empty.rrd: $(rrd_binary) create speed-empty.rrd --start 920804400 \ DS:speed:COUNTER:600:U:U \ RRA:AVERAGE:0.5:1:24 \ RRA:AVERAGE:0.5:6:10 speed.rrd: speed-empty.rrd cp speed-empty.rrd speed.rrd $(rrd_binary) update speed.rrd \ 920804700:12345 920805000:12357 920805300:12363 \ 920805600:12363 920805900:12363 920806200:12373 \ 920806500:12383 920806800:12393 920807100:12399 \ 920807400:12405 920807700:12411 920808000:12415 \ 920808300:12420 920808600:12422 920808900:12423 speed.png: speed.rrd $(rrd_binary) graph speed.png \ --start 920804400 --end 920808000 \ --vertical-label m/s \ DEF:myspeed=speed.rrd:speed:AVERAGE \ CDEF:realspeed=myspeed,1000,* \ LINE2:realspeed#FF0000 rrd_updater_fetch.txt: speed.rrd $(rrd_binary) fetch speed.rrd AVERAGE \ --start 920804400 --end 920809200 >rrd_updater_fetch.txt speed-dump.xml: speed.rrd $(rrd_binary) dump speed.rrd >speed-dump.xml moreDS-empty.rrd: $(rrd_binary) create moreDS-empty.rrd --start 920804400 \ DS:speed1:COUNTER:600:U:U \ DS:speed2:COUNTER:600:U:U \ RRA:AVERAGE:0.5:1:24 \ RRA:AVERAGE:0.5:6:10 cp moreDS-empty.rrd moreDS-updater.rrd $(rrd_binary) update moreDS-updater.rrd \ 920804700:12345:11340 920805000:12357:11357 920805300:12363:11363 $(rrd_binary) fetch moreDS-updater.rrd AVERAGE \ --start 920804400 --end 920808000 >moreDS_updater_fetch.txt rm moreDS-updater.rrd moreDS.rrd: $(rrd_binary) create moreDS.rrd --start 920804400 \ DS:speed1:COUNTER:600:U:U \ DS:speed2:COUNTER:600:U:U \ RRA:AVERAGE:0.5:1:24 \ RRA:AVERAGE:0.5:6:10 $(rrd_binary) update moreDS.rrd \ 920804700:12345:11340 920805000:12357:11357 920805300:12363:11363 \ 920805600:12363:11364 920805900:12363:11364 920806200:12373:11373 \ 920806500:12383:11373 920806800:12393:11393 920807100:12399:11399 \ 920807400:12405:11405 920807700:12411:11411 920808000:12415:11415 \ 920808300:12420:11420 920808600:12422:11422 920808900:12423:11423 moreDS_fetch.txt: moreDS.rrd $(rrd_binary) fetch moreDS.rrd AVERAGE \ --start 920804400 --end 920808000 >moreDS_fetch.txt php-rrd-1.1.3/rrd-1.1.3/tests/data/definition.inc000066400000000000000000000007301226725740500212250ustar00rootroot00000000000000 --FILE-- --EXPECTF-- rrd extension loaded php-rrd-1.1.3/rrd-1.1.3/tests/rrd_002.phpt000066400000000000000000000013271226725740500175410ustar00rootroot00000000000000--TEST-- RRDGraph test --SKIPIF-- --FILE-- setOptions(array( "--start" => "920804400", "--end" => 920808000, "--vertical-label" => "m/s", "DEF:myspeed=$data_updatedDb:speed:AVERAGE", "CDEF:realspeed=myspeed,1000,*", "LINE2:realspeed#FF0000" )); var_dump($graphObj->save()); var_dump(file_exists($outputPngFile)); ?> --EXPECTF-- array(3) { ["xsize"]=> int(497) ["ysize"]=> int(%d) ["calcpr"]=> NULL } bool(true) php-rrd-1.1.3/rrd-1.1.3/tests/rrd_003.phpt000066400000000000000000000006201226725740500175350ustar00rootroot00000000000000--TEST-- RRDCreator test --SKIPIF-- --FILE-- addDataSource("speed:COUNTER:600:U:U"); $creator->addArchive("AVERAGE:0.5:1:24"); $creator->addArchive("AVERAGE:0.5:6:10"); $creator->save(); var_dump(file_exists($rrdFile)); ?> --EXPECTF-- bool(true) php-rrd-1.1.3/rrd-1.1.3/tests/rrd_004.phpt000066400000000000000000000040441226725740500175420ustar00rootroot00000000000000--TEST-- RRDUpdater test --SKIPIF-- --FILE-- update(array("speed" => "12345"), "920804700"); $updator->update(array("speed" => "12357"), "920805000"); $updator->update(array("speed" => "12363"), "920805300"); $updator->update(array("speed" => "12363"), "920805600"); $updator->update(array("speed" => "12363"), "920805900"); $updator->update(array("speed" => "12373"), "920806200"); $updator->update(array("speed" => "12383"), "920806500"); $updator->update(array("speed" => "12393"), "920806800"); $updator->update(array("speed" => "12399"), "920807100"); $updator->update(array("speed" => "12405"), "920807400"); $updator->update(array("speed" => "12411"), "920807700"); $updator->update(array("speed" => "12415"), "920808000"); $updator->update(array("speed" => "12420"), "920808300"); $updator->update(array("speed" => "12422"), "920808600"); $updator->update(array("speed" => "12423"), "920808900"); //graph just for "visual test" if test fails $command = "$rrdtool_bin graph " . dirname(__FILE__) . "/rrd_updater_test.png " . "--start 920804400 --end 920808000 " . "--vertical-label m/s " . "DEF:myspeed=$rrdFile:speed:AVERAGE " . "CDEF:realspeed=myspeed,1000,* " . "LINE2:realspeed#FF0000"; echo "exporting rrd_updater_test.png via exec\n"; exec($command); $command = "$rrdtool_bin fetch $rrdFile AVERAGE --start 920804400 --end 920809200"; $output = array(); exec($command, $output); $originalFetch = file($data_updaterTxt, FILE_IGNORE_NEW_LINES); echo "comparing original and current fetch\n"; var_dump(array_diff($output, $originalFetch)); ?> --EXPECTF-- exporting rrd_updater_test.png via exec comparing original and current fetch array(0) { } php-rrd-1.1.3/rrd-1.1.3/tests/rrd_005.phpt000066400000000000000000000020611226725740500175400ustar00rootroot00000000000000--TEST-- RRDUpdater default timestamp test --SKIPIF-- --FILE-- update(array("speed" => "12345")); sleep(1); $updator->update(array("speed" => "12357")); sleep(1); $updator->update(array("speed" => "12363")); sleep(1); $updator->update(array("speed" => "12363")); sleep(1); $updator->update(array("speed" => "12363")); sleep(1); //mostly for "visual test" $command = "$rrdtool_bin graph " . dirname(__FILE__) . "/rrd_updater_default_val.png " . "--start -5s --end now " . "--vertical-label m/s " . "DEF:myspeed=$rrdFile:speed:AVERAGE " . "CDEF:realspeed=myspeed,1000,* " . "LINE2:realspeed#FF0000"; echo "exporting graph via exec\n"; exec($command); ?> --EXPECTF-- exporting %s via exec php-rrd-1.1.3/rrd-1.1.3/tests/rrd_006.phpt000066400000000000000000000021721226725740500175440ustar00rootroot00000000000000--TEST-- rrd_update test --SKIPIF-- --FILE-- --EXPECTF-- exporting rrd_update_1.png via exec bool(true) php-rrd-1.1.3/rrd-1.1.3/tests/rrd_007.phpt000066400000000000000000000005041226725740500175420ustar00rootroot00000000000000--TEST-- rrd_create test --SKIPIF-- --FILE-- --EXPECTF-- bool(true) php-rrd-1.1.3/rrd-1.1.3/tests/rrd_008.phpt000066400000000000000000000017561226725740500175550ustar00rootroot00000000000000--TEST-- rrd_graph test --SKIPIF-- include('skipif.inc'); include('rrdtool-bin.inc'); include('data/definition.inc'); if (!file_exists($data_updatedDb)) { die("skip $data_updatedDb doesnt' exist"); } ?> --FILE-- --EXPECTF-- exporting image via exec array(3) { ["xsize"]=> int(497) ["ysize"]=> int(%d) ["calcpr"]=> NULL } php-rrd-1.1.3/rrd-1.1.3/tests/rrd_009.phpt000066400000000000000000000004221226725740500175430ustar00rootroot00000000000000--TEST-- rrd_error test --SKIPIF-- --FILE-- --EXPECTF-- string(31) "can't parse argument 'badParam'" bool(false)php-rrd-1.1.3/rrd-1.1.3/tests/rrd_010.phpt000066400000000000000000000031601226725740500175350ustar00rootroot00000000000000--TEST-- rrd_fetch test --SKIPIF-- include('skipif.inc'); include('data/definition.inc'); if (!file_exists($data_moreDSDb)) { die("skip $data_moreDSDb doesnt' exist"); } --FILE-- --EXPECTF-- array(4) { ["start"]=> int(920804400) ["end"]=> int(920808300) ["step"]=> int(300) ["data"]=> array(2) { ["speed1"]=> array(13) { [920804700]=> float(NAN) [920805000]=> float(0.04) [920805300]=> float(0.02) [920805600]=> float(0) [920805900]=> float(0) [920806200]=> float(0.033333333333333) [920806500]=> float(0.033333333333333) [920806800]=> float(0.033333333333333) [920807100]=> float(0.02) [920807400]=> float(0.02) [920807700]=> float(0.02) [920808000]=> float(0.013333333333333) [920808300]=> float(0.016666666666667) } ["speed2"]=> array(13) { [920804700]=> float(NAN) [920805000]=> float(0.056666666666667) [920805300]=> float(0.02) [920805600]=> float(0.0033333333333333) [920805900]=> float(0) [920806200]=> float(0.03) [920806500]=> float(0) [920806800]=> float(0.066666666666667) [920807100]=> float(0.02) [920807400]=> float(0.02) [920807700]=> float(0.02) [920808000]=> float(0.013333333333333) [920808300]=> float(0.016666666666667) } } }php-rrd-1.1.3/rrd-1.1.3/tests/rrd_011.phpt000066400000000000000000000007141226725740500175400ustar00rootroot00000000000000--TEST-- rrd_first test --SKIPIF-- --FILE-- --EXPECTF-- int(920802000) int(920791800) bool(false) bool(false) php-rrd-1.1.3/rrd-1.1.3/tests/rrd_012.phpt000066400000000000000000000026331226725740500175430ustar00rootroot00000000000000--TEST-- rrd_info test --SKIPIF-- --FILE-- --EXPECTF-- array(27) { ["filename"]=> string(%d) %s ["rrd_version"]=> string(4) %s ["step"]=> int(300) ["last_update"]=> int(920808900) ["header_size"]=> int(%d) ["ds[speed].index"]=> int(0) ["ds[speed].type"]=> string(7) "COUNTER" ["ds[speed].minimal_heartbeat"]=> int(600) ["ds[speed].min"]=> float(NAN) ["ds[speed].max"]=> float(NAN) ["ds[speed].last_ds"]=> string(5) "12423" ["ds[speed].value"]=> float(0) ["ds[speed].unknown_sec"]=> int(0) ["rra[0].cf"]=> string(7) "AVERAGE" ["rra[0].rows"]=> int(24) ["rra[0].cur_row"]=> int(%d) ["rra[0].pdp_per_row"]=> int(1) ["rra[0].xff"]=> float(0.5) ["rra[0].cdp_prep[0].value"]=> float(NAN) ["rra[0].cdp_prep[0].unknown_datapoints"]=> int(0) ["rra[1].cf"]=> string(7) "AVERAGE" ["rra[1].rows"]=> int(10) ["rra[1].cur_row"]=> int(%d) ["rra[1].pdp_per_row"]=> int(6) ["rra[1].xff"]=> float(0.5) ["rra[1].cdp_prep[0].value"]=> float(0.026666666666667) ["rra[1].cdp_prep[0].unknown_datapoints"]=> int(0) } bool(true) php-rrd-1.1.3/rrd-1.1.3/tests/rrd_013.phpt000066400000000000000000000004351226725740500175420ustar00rootroot00000000000000--TEST-- rrd_last test --SKIPIF-- include('skipif.inc'); include('data/definition.inc'); if (!file_exists($data_updatedDb)) { die("skip $data_updatedDb doesn't exist"); } --FILE-- --EXPECTF-- int(920808900)php-rrd-1.1.3/rrd-1.1.3/tests/rrd_014.phpt000066400000000000000000000015151226725740500175430ustar00rootroot00000000000000--TEST-- rrd_lastupdate test --SKIPIF-- --FILE-- --EXPECTF-- array(4) { ["last_update"]=> int(920808900) ["ds_cnt"]=> int(1) ["ds_navm"]=> array(1) { [0]=> string(5) "speed" } ["data"]=> array(1) { [0]=> string(5) "12423" } } array(4) { ["last_update"]=> int(920808900) ["ds_cnt"]=> int(2) ["ds_navm"]=> array(2) { [0]=> string(6) "speed1" [1]=> string(6) "speed2" } ["data"]=> array(2) { [0]=> string(5) "12423" [1]=> string(5) "11423" } }php-rrd-1.1.3/rrd-1.1.3/tests/rrd_015.phpt000066400000000000000000000012001226725740500175330ustar00rootroot00000000000000--TEST-- rrd_restore test --SKIPIF-- --FILE-- --EXPECTF-- bool(true) bool(true) bool(true) php-rrd-1.1.3/rrd-1.1.3/tests/rrd_016.phpt000066400000000000000000000010601226725740500175400ustar00rootroot00000000000000--TEST-- rrd_tune test --SKIPIF-- --FILE-- --EXPECTF-- bool(true) bool(false) bool(true) %sphp-rrd-1.1.3/rrd-1.1.3/tests/rrd_017.phpt000066400000000000000000000037271226725740500175550ustar00rootroot00000000000000--TEST-- rrd_xport test --SKIPIF-- --FILE-- --EXPECTF-- array(4) { ["start"]=> int(920804700) ["end"]=> int(920808300) ["step"]=> int(300) ["data"]=> array(2) { [0]=> array(2) { ["legend"]=> string(7) "myspeed" ["data"]=> array(13) { [920804700]=> float(NAN) [920805000]=> float(0.04) [920805300]=> float(0.02) [920805600]=> float(0) [920805900]=> float(0) [920806200]=> float(0.033333333333333) [920806500]=> float(0.033333333333333) [920806800]=> float(0.033333333333333) [920807100]=> float(0.02) [920807400]=> float(0.02) [920807700]=> float(0.02) [920808000]=> float(0.013333333333333) [920808300]=> float(0.016666666666667) } } [1]=> array(2) { ["legend"]=> string(9) "realspeed" ["data"]=> array(13) { [920804700]=> float(NAN) [920805000]=> float(40) [920805300]=> float(20) [920805600]=> float(0) [920805900]=> float(0) [920806200]=> float(33.333333333333) [920806500]=> float(33.333333333333) [920806800]=> float(33.333333333333) [920807100]=> float(20) [920807400]=> float(20) [920807700]=> float(20) [920808000]=> float(13.333333333333) [920808300]=> float(16.666666666667) } } } } php-rrd-1.1.3/rrd-1.1.3/tests/rrd_018.phpt000066400000000000000000000017061226725740500175510ustar00rootroot00000000000000--TEST-- RRDGraph saveVerbose test --SKIPIF-- --FILE-- setOptions(array( "--start" => "920804400", "--end" => 920808000, "--vertical-label" => "m/s", "DEF:myspeed=$rrdFile:speed:AVERAGE", "CDEF:realspeed=myspeed,1000,*", "LINE2:realspeed#FF0000" )); var_dump($graphObj->saveVerbose()); ?> --EXPECTF-- array(10) { ["graph_left"]=> int(67) ["graph_top"]=> int(%d) ["graph_width"]=> int(400) ["graph_height"]=> int(100) ["image_width"]=> int(497) ["image_height"]=> int(%d) ["graph_start"]=> int(920804400) ["graph_end"]=> int(920808000) ["value_min"]=> float(0) ["value_max"]=> float(40) } php-rrd-1.1.3/rrd-1.1.3/tests/rrd_019.phpt000066400000000000000000000021651226725740500175520ustar00rootroot00000000000000--TEST-- RRDGraph saveVerbose full export test --SKIPIF-- --FILE-- setOptions(array( "--start" => "920804400", "--end" => 920808000, "--vertical-label" => "m/s", "DEF:myspeed=$rrdFile:speed:AVERAGE", "CDEF:realspeed=myspeed,1000,*", "LINE2:realspeed#FF0000" )); $output = $graphObj->saveVerbose(); $imgData = $output["image"]; unset($output["image"]); //output without img data var_dump($output); //detection of correct PNG header var_dump(substr($imgData, 0, 8) == "\x89PNG\x0d\x0a\x1a\x0a"); ?> --EXPECTF-- array(10) { ["graph_left"]=> int(67) ["graph_top"]=> int(%d) ["graph_width"]=> int(400) ["graph_height"]=> int(100) ["image_width"]=> int(497) ["image_height"]=> int(%d) ["graph_start"]=> int(920804400) ["graph_end"]=> int(920808000) ["value_min"]=> float(0) ["value_max"]=> float(40) } bool(true) php-rrd-1.1.3/rrd-1.1.3/tests/rrd_020.phpt000066400000000000000000000003771226725740500175450ustar00rootroot00000000000000--TEST-- rrd_version test --SKIPIF-- --FILE-- = 2); ?> --EXPECTF-- string(%i) "%s" bool(true) bool(true) php-rrd-1.1.3/rrd-1.1.3/tests/rrd_021.phpt000066400000000000000000000022271226725740500175420ustar00rootroot00000000000000--TEST-- RRDUpdater more data source test --SKIPIF-- --FILE-- update(array("speed1" => 12345, "speed2" => 11340), 920804700); $updator->update(array("speed1" => 12357, "speed2" => 11357), 920805000); $updator->update(array("speed1" => 12363, "speed2" => 11363), 920805300); //mostly for "visual test" $command = "$rrdtool_bin fetch $rrdFile AVERAGE " . "--start 920804400 --end 920808000 " . ">" . dirname(__FILE__) . "/rrd_updater_moreDS_fetch.txt"; $output = array(); exec($command, $output); $originalFetch = file($data_moreDSUpdaterTxt, FILE_IGNORE_NEW_LINES); echo "comparing original and current fetch\n"; var_dump(array_diff($output, $originalFetch)); ?> --EXPECTF-- comparing original and current fetch array(0) { } php-rrd-1.1.3/rrd-1.1.3/tests/rrd_022.phpt000066400000000000000000000003541226725740500175420ustar00rootroot00000000000000--TEST-- rrdc_disconnect test --SKIPIF-- = 1.4"); } ?> --FILE-- --EXPECTF-- NULL php-rrd-1.1.3/rrd-1.1.3/tests/rrdtool-bin.inc.in000066400000000000000000000001621226725740500210230ustar00rootroot00000000000000 php-rrd-1.1.3/rrd-1.1.3/tests/skipif.inc000066400000000000000000000001241226725740500174460ustar00rootroot00000000000000