33
44// to send a metric to ddog
55char * metrictoddog (
6- OCIExtProcContext * ctx ,
7- char * name , // pointer to name -- name of the metric
8- short name_i , // null status of name
9- int * metric , // pointer to metric -- number to be sent to the metric
10- short metric_i , // null status of metric
11- char * kind , // pointer to string1
12- short kind_i , // null status of string1
13- char * tag , // pointer to string1
14- short tag_i , // null status of string1
15- short * ret_i , // pointer to indicator null or not null
16- short * ret_l // len of return
6+ OCIExtProcContext * ctx ,
7+ char * name , // pointer to name -- name of the metric
8+ short name_i , // null status of name
9+ int * metric , // pointer to metric -- number to be sent to the metric
10+ short metric_i , // null status of metric
11+ char * kind , // pointer to string1
12+ short kind_i , // null status of string1
13+ char * tag , // pointer to string1
14+ short tag_i , // null status of string1
15+ short * ret_i , // pointer to indicator null or not null
16+ short * ret_l // len of return
1717 )
1818{
19- char * tmp ;
20- short len ;
21- char * metricname ;
22- char * themetric ; // to store the metric we will send to datadog
23- char * thekind ; // to store the metric we will send to datadog
24-
25- // Check for null inputs
26- if (name_i == OCI_IND_NULL )
27- {
28- * ret_i = (short )OCI_IND_NULL ;
29-
30- // PL/SQL has no notion of a NULL ptr, so return a zero-byte string.
31- tmp = OCIExtProcAllocCallMemory (ctx , 1 );
32- tmp [0 ] = '\0' ;
33-
34- return (tmp );
35- }
36-
37- // the main part
38-
39- strcat (metricname , name );
40-
41- if (kind_i == OCI_IND_NOTNULL )
42- {
43- asprintf (& thekind ,"%s" ,kind );
44- }
45-
46- if (kind_i == OCI_IND_NULL )
47- {
48- asprintf (& thekind ,"%s" ,"g" );
49- }
50-
51- if (tag_i == OCI_IND_NULL )
52- {
53- asprintf (& themetric ,"%s:%d|%s|" ,metricname , metric , thekind );
54- }
19+ char * tmp ;
20+ short len ;
21+ char * metricname ;
22+ char * themetric ; // to store the metric we will send to datadog
23+ char * thekind ; // to store the kind we will send to datadog
24+
25+ // Check for null inputs
26+ if (name_i == OCI_IND_NULL )
27+ {
28+ * ret_i = (short )OCI_IND_NULL ;
29+
30+ // PL/SQL has no notion of a NULL ptr, so return a zero-byte string.
31+ tmp = OCIExtProcAllocCallMemory (ctx , 1 );
32+ tmp [0 ] = '\0' ;
5533
56- if (tag_i == OCI_IND_NOTNULL )
57- {
58- asprintf (& themetric ,"%s:%d|%s|#%s" ,metricname , metric , thekind ,tag );
59- }
34+ return (tmp );
35+ }
6036
61- udp (8125 , themetric );
37+ // the main part
38+ strcat (metricname , name );
6239
40+ if (kind_i == OCI_IND_NOTNULL )
41+ {
42+ asprintf (& thekind ,"%s" ,kind );
43+ } else {
44+ asprintf (& thekind ,"%s" ,"g" ); // no kind, we default to gauge
45+ }
6346
64- // the reply part
65- // the text for return
47+ if (tag_i == OCI_IND_NOTNULL )
48+ {
49+ asprintf (& themetric ,"%s:%d|%s|#%s" ,metricname , metric , thekind ,tag );
50+ } else {
51+ asprintf (& themetric ,"%s:%d|%s|" ,metricname , metric , thekind );
52+ }
6653
67- char * reply = "done" ;
54+ udp ( 8125 , themetric ); // we fire the metric to datadog
6855
69- // Allocate memory for result string, including NULL terminator.
70- len = strlen (reply );
71- tmp = OCIExtProcAllocCallMemory (ctx , len + 1 );
72- tmp [0 ] = '\0' ;
56+ // the reply part
57+ char * reply = "done" ; // as udp is stateless, we assume all went fine
7358
74- // set the reply
75- strcat (tmp , reply );
59+ // Allocate memory for result string, including NULL terminator.
60+ len = strlen (reply );
61+ tmp = OCIExtProcAllocCallMemory (ctx , len + 1 );
62+ tmp [0 ] = '\0' ;
7663
77- // Set NULL indicator and length.
78- * ret_i = (short )OCI_IND_NOTNULL ;
79- * ret_l = len ;
64+ // set the reply
65+ strcat (tmp , reply );
8066
81- // Return pointer, which PL/SQL frees later .
82- return tmp ;
83- }
67+ // Set ret indicator and length .
68+ * ret_i = ( short ) OCI_IND_NOTNULL ;
69+ * ret_l = len ;
8470
71+ // Return pointer, which PL/SQL frees later.
72+ return tmp ;
73+ }
0 commit comments