Skip to content

Commit eb227f4

Browse files
committed
Move print statement to outside of main function
Should help with web server compatibility Signed-off-by: Monica Hanson <mhanson@monicarose.tech>
1 parent a28b913 commit eb227f4

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

iptables.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,13 @@ def gather_tables():
5555
iptables_packet_lines.append('%s_packets_total{table="%s",chain="%s",line_number=%s,target="%s",prot="%s",in="%s",out="%s",src="%s",dest="%s",opt="%s"} %s' % (ip_proto,table,l_chain_name,l_line_number,l_target,l_prot,l_in,l_out,l_src,l_dest,l_options,l_packets))
5656
iptables_byte_lines.append('%s_bytes_total{table="%s",chain="%s",line_number=%s,target="%s",prot="%s",in="%s",out="%s",src="%s",dest="%s",opt="%s"} %s' % (ip_proto,table,l_chain_name,l_line_number,l_target,l_prot,l_in,l_out,l_src,l_dest,l_options,l_bytes))
5757

58-
print(f'# HELP {ip_proto}_packets_total packet counters for {ip_proto} rules.')
59-
print(f'# TYPE {ip_proto}_packets_total counter')
60-
for line in iptables_packet_lines:
61-
print(line)
58+
iptables_packet_lines.append(f'# HELP {ip_proto}_packets_total packet counters for {ip_proto} rules.')
59+
iptables_packet_lines.append(f'# TYPE {ip_proto}_packets_total counter')
6260

63-
print(f'# HELP {ip_proto}_bytes_total byte counters for {ip_proto} rules.')
64-
print(f'# TYPE {ip_proto}_bytes_total counter')
65-
for line in iptables_byte_lines:
66-
print(line)
61+
iptables_byte_lines.append(f'# HELP {ip_proto}_bytes_total byte counters for {ip_proto} rules.')
62+
iptables_byte_lines.append(f'# TYPE {ip_proto}_bytes_total counter')
63+
64+
return '\n'.join(iptables_packet_lines) + '\n' + '\n'.join(iptables_byte_lines)
6765

6866
if __name__ == "__main__":
69-
gather_tables()
67+
print(gather_tables())

0 commit comments

Comments
 (0)