]> git.ipfire.org Git - collecty.git/blob - src/_collecty/_collectymodule.h
f34a31433d82fcb47d0159583e5993e3cb26faf8
[collecty.git] / src / _collecty / _collectymodule.h
1 /*
2 * collecty
3 * Copyright (C) 2015 IPFire Team (www.ipfire.org)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <Python.h>
20
21 #include <atasmart.h>
22 #include <linux/hdreg.h>
23 #include <mntent.h>
24 #include <oping.h>
25 #include <sensors/error.h>
26 #include <sensors/sensors.h>
27
28 #define MODEL_SIZE 40
29 #define SERIAL_SIZE 20
30
31 #define PING_HISTORY_SIZE 1024
32 #define PING_DEFAULT_COUNT 10
33 #define PING_DEFAULT_TIMEOUT 8
34
35 /* block devices */
36 typedef struct {
37 PyObject_HEAD
38 char* path;
39 struct hd_driveid identity;
40 SkDisk* disk;
41 } BlockDevice;
42
43 PyTypeObject BlockDeviceType;
44
45 void BlockDevice_dealloc(BlockDevice* self);
46 int BlockDevice_get_identity(BlockDevice* device);
47 int BlockDevice_smart_is_available(BlockDevice* device);
48 int BlockDevice_check_sleep_mode(BlockDevice* device);
49 PyObject * BlockDevice_new(PyTypeObject* type, PyObject* args, PyObject* kwds);
50 int BlockDevice_init(BlockDevice* self, PyObject* args, PyObject* kwds);
51 PyObject* BlockDevice_get_path(PyObject* self);
52 PyObject* BlockDevice_get_model(PyObject* self);
53 PyObject* BlockDevice_get_serial(PyObject* self);
54 PyObject* BlockDevice_is_smart_supported(PyObject* self);
55 PyObject* BlockDevice_is_awake(PyObject* self);
56 PyObject* BlockDevice_get_bad_sectors(PyObject* self);
57 PyObject* BlockDevice_get_temperature(PyObject* self);
58
59 /* ping */
60 PyObject* PyExc_PingError;
61 PyObject* PyExc_PingAddHostError;
62
63 typedef struct {
64 PyObject_HEAD
65 pingobj_t* ping;
66 const char* host;
67 struct {
68 double history[PING_HISTORY_SIZE];
69 size_t history_index;
70 size_t history_size;
71 size_t packets_sent;
72 size_t packets_rcvd;
73 double average;
74 double stddev;
75 double loss;
76 } stats;
77 } PingObject;
78
79 PyTypeObject PingType;
80
81 void Ping_dealloc(PingObject* self);
82 void Ping_init_stats(PingObject* self);
83 PyObject* Ping_new(PyTypeObject* type, PyObject* args, PyObject* kwds);
84 int Ping_init(PingObject* self, PyObject* args, PyObject* kwds);
85 double Ping_compute_average(PingObject* self);
86 double Ping_compute_stddev(PingObject* self, double mean);
87 PyObject* Ping_ping(PingObject* self, PyObject* args, PyObject* kwds);
88 PyObject* Ping_get_packets_sent(PingObject* self);
89 PyObject* Ping_get_packets_rcvd(PingObject* self);
90 PyObject* Ping_get_average(PingObject* self);
91 PyObject* Ping_get_stddev(PingObject* self);
92 PyObject* Ping_get_loss(PingObject* self);
93
94 /* sensors */
95 typedef struct {
96 PyObject_HEAD
97 const sensors_chip_name* chip;
98 const sensors_feature* feature;
99 } SensorObject;
100
101 PyTypeObject SensorType;
102
103 void Sensor_dealloc(SensorObject* self);
104 PyObject* Sensor_new(PyTypeObject* type, PyObject* args, PyObject* kwds);
105 int Sensor_init(SensorObject* self, PyObject* args, PyObject* kwds);
106 PyObject* Sensor_get_label(SensorObject* self);
107 PyObject* Sensor_get_name(SensorObject* self);
108 PyObject* Sensor_get_type(SensorObject* self);
109 PyObject* Sensor_get_bus(SensorObject* self);
110 PyObject* Sensor_return_value(SensorObject* sensor, sensors_subfeature_type subfeature_type);
111 PyObject* Sensor_get_value(SensorObject* self);
112 PyObject* Sensor_get_critical(SensorObject* self);
113 PyObject* Sensor_get_maximum(SensorObject* self);
114 PyObject* Sensor_get_minimum(SensorObject* self);
115 PyObject* Sensor_get_high(SensorObject* self);
116
117 PyObject* _collecty_sensors_init();
118 PyObject* _collecty_sensors_cleanup();
119 PyObject* _collecty_get_detected_sensors(PyObject* o, PyObject* args);
120
121 /* utils */
122 int _collecty_mountpoint_is_virtual(const struct mntent* mp);
123 PyObject* _collecty_get_mountpoints();